ERC1155 Constructor Question

Hoping to get some clarity on how the ERC1155 constructor works....

1.)I've seen a ton of tutorials of ERC1155 contracts written that mint a bunch of tokens in the constructor. The ERC1155 part of the constructor also takes the token URI of those minted tokens upon deployment.

For example the constructor of the contract would look like this...

 constructor() public ERC1155("https://bafybeihul6zsmbzyrgmjth3ynkmchepyvyhcwecn2yxc57ppqgpvr35zsq.ipfs.dweb.link/{id}.json") {
        _mint(msg.sender, CHARIZARD, 100, "");
        _mint(msg.sender, IVYSAUR, 100, "");
        _mint(msg.sender, VENUSAUR, 100, "");
        _mint(msg.sender, CHARMANDER, 100, "");
    }

So the above is minting is passing in the uri and then minting a bunch of tokens. But what if you don't want to mint any tokens in the constructor? IN other words you don't want your contract to be a set of NfT's that other people can mint but rather a contract that allows them to create/mint their own tokens/nft's (not someone elses. If you want to set up an ERC1155 contract that does this than do you just pass an empty string in the ERC1155 part of the constructor like this and don't mint anything?....

 constructor() public ERC1155("") {
  }

If the above is okay, then what happens next? The user would simply calls the mint function which can mint his own tokens and setTokenUri in one shot?

1 Like

Well, you'll need to expose the _mint function in your contract in some way, for example:

function mint(address to, uint256 id, uint256 amount, bytes memory data) external {
    _mint(to, id, amount, data);
}

But that doesn't make too much sense financially-wise.

It really depends on your product requirements, but the most sensible one which I'm aware of is to mint all known NFTs well ahead in advance, in order for them to attain a real market value.

For example, you deploy this:

contract MyNFT is ERC1155 {
    constructor(uint256[] calldata ids, uint256[] calldata amounts) ERC1155("YourURL") {
        _mintBatch(msg.sender, ids, amounts, "");
    }
}

And after deployment, you can transfer those NFT as desired.

1 Like