Reputation: 83
Is it possible to mint all tokens to the contract address as soon as the contract is deployed?
I have a collection of 100 NFTs which need to be visible immediately under the collection address in OpenSea but I see that the NFTs appear there only when minted to a wallet address. My initial idea was to mint everything to the owner's address so that all NFTs would be available under the collection...
Any idea on how to implement it?
Upvotes: 0
Views: 825
Reputation: 43481
You can mint tokens during deployment, the contract address is available through the address(this)
expression.
pragma solidity ^0.8;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract MyCollection is ERC721 {
constructor() ERC721("CollectionName", "Symbol") {
// mint 100 tokens to the contract address on deployment
for (uint i = 1; i <= 100; i++) {
_mint(address(this), i);
}
}
}
It depends on implementation of OpenSea and other marketplaces if they accept such NFTs minted on deployment - or if they don't recognize these tokens.
Upvotes: 1