How to build and use XRC-1155 tokens

  1. Batch Transfer: Transfer multiple assets in a single call.
  2. Batch Balance: Get the balances of multiple assets in a single call.
  3. Batch Approval: Approve all tokens to an address.
  4. XIP-165 Support: Declare supported interfaces.
  5. Hooks: Receive tokens hook.
  6. NFT support: If supply is only 1, treat it as NFT.
  7. Safe Transfer Rules: Set of rules for secure transfer.
// XRC-20function transferFrom(address from, address to, uint256 value) external returns (bool);
// XRC-1155ifunction safeBatchTransferFrom(address _from,address _to,uint256[] calldata _ids,uint256[] calldata _values,bytes calldata _data) external;
  1. Transfer 100 tokens with id 3 from _from to _to.
  2. Transfer 200 tokens with id 6 from _from to _to.
  3. Transfer 5 tokens with id 13 from _from to _to.
  • Why is it called ‘safe’-BatchTransferFrom? — See section 7 below about safe transfer rules.
  • Why is it not returning boolean? — The transaction reverts on failure
  • What is the bytes data field? — Just as in XRC-777, you can pass arbitrary data along with the call which will also be passed to the receive hook.
// XRC-20function balanceOf(address owner) external view returns (uint256);
// XRC-1155function balanceOfBatch(address[] calldata _owners,uint256[] calldata _ids) external view returns (uint256[] memory);
// XRC-1155function setApprovalForAll(address _operator,bool _approved) external;
// XRC-1155
function isApprovedForAll(address _owner,address _operator) external view returns (bool);
bytes4(keccak256(“onXRC1155BatchReceived(address,address,uint256[],uint256[],bytes)”))
address _operator,address _from,uint256[] calldata _ids,uint256[] calldata _values,bytes calldata _data) external returns(bytes4);
  1. The caller must be approved to spend the tokens for the _from address or the caller must equal _from.
  2. The transfer call must revert if
  • _to address is 0.
  • length of _ids is not the same as the length of _values.
  • any of the balance(s) of the holder(s) for token(s) in _ids is lower than the respective amount(s) in _values sent to the recipient.
  • any other error occurs.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store