ERC-1155 Token Contract APIs

You can use the following methods related to token functionality in ERC-1155 token contracts.

Token Configuration Methods

__ERC1155Token_init
This method is called when a token contract is deployed. This method can be called only by a Token Admin.
Parameters:
  • uri: string – The URI for all token types.

Token Setup Methods

saveNFTClass
This method saves NFT class information on the ledger. This method can be called only by a Token Admin.
Parameters:
  • classInfo: NFTClassInfo – The account contract address, which varies depending on whether the NFT is whole or fractional. Whole NFT:
    {
        "nftClassId": (BigInt(1)),
        "tokenName": "ArtCollection2",
        "tokenDesc": "this is art collection contract",
        "tokenStandard": "erc1155",
        "tokenUnit": 0,
        "behaviors": ["mintable", "burnable", "transferable", "roles", "indivisible"],
        "divisible": { "decimals": 0 },
        "mintable": { "maxMintQuantity": 2 }
    }
    Fractional NFT:
     "nftClassId": (BigInt(0)),
      tokenName": "ArtCollection",
      "tokenDesc": "this is art collection contract",
      "tokenStandard": "erc1155",
      "tokenUnit": 1,
      "behaviors": ["mintable", "burnable", "transferable", "roles", "divisible"],
      "divisible": { "decimals": 0 },
      "mintable": { "maxMintQuantity": 1 }
createNonFungibleToken
This method mints NFTs based on the saved NFT class information. This method can be called by a user with the minter role or by the Token Admin.
Parameters:
  • token: uint256 – The ID of the NFT, which contains NFT class information. The top 128 bits of the tokenId parameter represent the NFT class ID, while the bottom 128 bits represent the unique index of the NFT.
  • quantity: uint256 – The amount of the NFT to mint (create).
createFungibleToken
This method is called when the token contract is deployed. This method can be called only by the Token Admin.
Parameters:
  • tokenID: ERC1155Token – The fungible token definition to record in the ledger, as shown in the following example.
    "tokenId": BigInt(0),
     "tokenName": "wcbdc",
     "tokenDesc": "this is wcbdc token",
     "tokenStandard": "erc1155",
     "tokenType": 1,
     "tokenUnit": 1,
     "behaviors": ["mintable", "burnable", "transferable", "roles", "divisible"],
     "divisible": { "decimals": 2 },
     "quantity": 1,
     "mintable": { "maxMintQuantity": 1 }
getTokenById
This method gets the details for a specified token. This method can be called only by a Token Admin or by a token owner.
Parameters:
  • token: ERC1155Token – The token definition, as shown in the following example:
     "tokenId": BigInt(0),
     "tokenName": "wcbdc",
     "tokenDesc": "this is wcbdc token",
     "tokenStandard": "erc1155",
     "tokenType": 1,
     "tokenUnit": 1,
     "behaviors": ["mintable", "burnable", "transferable", "roles", "divisible"],
     "divisible": { "decimals": 2 },
     "quantity": 1,
     "mintable": { "maxMintQuantity": 1 }
  • metainfo: bytes – For fungible tokens, the metainfo parameter is empty. For whole NFTs, the metainfo parameter contains encoded data for the following structure:
    struct ERC1155WholeNFT {
        bool isBurned;
        bool isLocked;
        uint256 creationDate;
        uint256 quantity;
        address createdBy;
        address owner;
    }
    For fractional NFTs, the metainfo parameter contains encoded data for the following structure:
    struct ERC1155FractionalNFT {
        bool isBurned;
        bool isLocked;
        uint256 creationDate;
        uint256 quantity;
        address createdBy;
        Owners[] owners;
    }
getTokenDecimals
This method returns the number of decimals places that were configured for a token. This method can be called only by a Token Admin.
Parameters:
  • id: uint256 – The token ID.
Returns:
  • A uint8 value indicating the number of decimal places.
tokenIdOf
This method returns the token ID. This method can be called only by a Token Admin.
Parameters:
  • classId: uint256 – The NFT class ID.
  • serialId: uint256 – The serial ID in the NFT class.
Returns:
  • A uint256 value of the token ID.
balanceOf
This method returns the current token balance for a specified user. This method can be called only by a Token Admin or by the token owner.
Parameters:
  • account: string – The account address of the user.
  • id: uint256 – The token ID.
Returns:
  • A uint256 value indicating the current balance.
balanceOfBatch
This method returns the current token balances for a batch of specified users. This method can be called only by a Token Admin or by the token owner.
Parameters:
  • accounts: string[] – A list of account addresses of users.
  • ids: uint256[] – A list of token IDs.
Returns:
  • A uint256[] list of values indicating the current balances.
exists
This method checks whether a specified token exists. This method can be called only by a Token Admin.
Parameters:
  • id: uint256 – The token ID.
Returns:
  • A Boolean value (true or false).
totalSupply
This method returns the total supply of tokens in a contract. This method can be called only by a Token Admin.
Parameters:
  • id: uint256 (optional) – A token ID. If you do not specify a token ID, the total supply of all tokens in the contract is returned
Returns:
  • A uint256 value indicating the total supply.

Token Behavior Methods - Mintable Behavior

mintBatch
This method mints ERC-1155 tokens in batches. The tokens must already be intialized. This method can be called by any user with the minter role.
Parameters:
  • tokenIds: uint256[] – A list of token IDs to mint.
  • quantity: uint256[] – A corresponding list of token quantities to mint.
  • data: bytes – Additional data in byte format.

Token Behavior Methods - Burnable Behavior

burnBatch
This method burns ERC-1155 tokens in batches. The tokens must already be initialized. This method can be called by any user with the burner role.
Parameters:
  • tokenIds: uint256[] – A list of token IDs to burn.
  • quantity: uint256[] – A corresponding list of token quantities to burn.
  • data: bytes – Additional data in byte format.
burnNFT
This method burns NFTs. The token must already be initialized. This method can be called by any user with the burner role.
Parameters:
  • tokenId: uint256 – The ID of the token to burn.

Token Behavior Methods - Transferable Behavior

safeTransferFrom
This method can be called by any user with tokens to transfer them to another user.
Parameters:
  • from: string – The wallet address of the sender, which must not be zero.
  • to: string – The wallet address of the receiver, which must not be zero.
  • id: uint256 – The ID of the token to transfer.
  • value: uint256 – The quantity of tokens to transfer.
  • data: bytes – Additional data in byte format.
safeBatchTransferFrom
This method can be called by any user with tokens to transfer them in batches to another user.
Parameters:
  • from: string – The wallet address of the sender, which must not be zero.
  • to: string – The wallet address of the receiver, which must not be zero.
  • id: uint256[] – A list of IDs of tokens to transfer.
  • value: uint256[] – A corresponding list of quantities of tokens to transfer.
  • data: bytes – Additional data in byte format.

Token Behavior Methods - Delegable Behavior

setApprovalForAll
This method can be called by any user who owns tokens to grant or revoke permission for an operator to transfer the caller's tokens.
Parameters:
  • operator: string – The wallet address of the operator, which must not be zero.
  • approved: bool – A flag indicating whether the operator has permission to transfer the caller's tokens.
isApprovedForAll
This method can be called by any user who owns tokens to check whether a specified user has permission as an operator to transfer the caller's tokens.
Parameters:
  • account: string – The address of the user who granted or revoked permission for the operation to transfer their tokens.
  • operator: string – The wallet address of the operator, which must not be zero.
Returns:
  • A Boolean value (true or false) indicating whether the specified user has permission as an operator to transfer the caller's tokens.

Token Behavior Methods - Pausable Behavior

paused
This method checks whether a contract is paused. This method can be called only by any user.
Parameters:
  • None
pause
This method pauses a contract. This method can be called only by a Token Admin.
Parameters:
  • None
unpause
This method starts a paused contract. This method can be called only by a Token Admin.
Parameters:
  • None

Token Behavior Methods - Lockable Behavior

lockNFT
This method locks an NFT. This method can be called only by a user with the TOKEN_SYS_VAULT_ROLE role.
Parameters:
  • tokenId: uint256 – The ID of the token to lock.
isNFTLocked
This method checks whether an NFT is locked. This method can be called only by a user with the TOKEN_SYS_VAULT_ROLE role or by a Token Admin.
Parameters:
  • tokenId: uint256 – The ID of the token to check.
Returns:
  • A Boolean value (true or false) indicating whether the NFT is locked.

Context Management Methods

setContext
This method sets the token contract address for the account contract. This method can be called only by a Token Admin.
Parameters:
  • tokenAddress: address – The contract address of the deployed token, which must not be zero.
getContext
This method gets the token contract address for the account contract. This method can be called by any user.
Parameters:
  • None
Returns
  • The token contract address
setGovernanceContext
This method sets the governance contract to use to manage the governance life cycle for the account contract. This method can be called only by a Token Admin.
Parameters:
  • uuid: string – The unique ID set by the digital assets Token Admin before contract deployment.
  • governance: address – The contract address of the deployed governance contract, which must not be zero.
getGovernanceContext
This method gets the governance context details. This method can be called by any user.
Parameters:
  • None
Returns
  • A governanceContext object.
Return Value Example:
{
    "governanceUUID": "abc-def",
    "governance": "0x0000000",
	"deploymentActive": "true"
}
isDeploymentActive
This method checks whether the deployment is active. This method can be called by any user.
Parameters:
  • None
Returns:
  • A Boolean value (true or false) indicating whether the deployment is active.