ERC1155 Example
The operation as a multi-token contract will be explained with a short example. Both fungible tokens and non-fungible tokens will be minted within one contract.
When calling the mint function, the ID of the token and the amount of tokens must be specified as parameters. It is to be noted that if an NFT will be generated, the amount has to be one.
Example: Twenty fungible tokens will be generated in the contract and three NFT. So, for the 20 fungible tokens, the mint function is called once with the parameters id = 0 and amount = 20. For the NFT it needs 3 calls of the mint function with the parameters:
1st Call | ID = 1 | Amount = 1 |
2nd Call | ID = 2 | Amount = 1 |
3rd Call | ID = 3 | Amount = 1 |
Since only the number of exactly one determines that a token is non-fungible, the logic of the contract must also prevent the accidental creation of further tokens with the same ID (for example, by using a counter variable).