ERC1155 Example

Published by Marianne Poser on

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 CallID = 1Amount = 1
2nd CallID = 2Amount = 1
3rd CallID = 3Amount = 1
Mint Function Parameters

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).

Categories: