ERC-1155 standard

ERC-1155 purpose

  • A standard to accommodate any combination of fungible tokens, non-fungible tokens, semi-fungible tokens
  • ERC721's token ID is a single non-fungible index and group of these non-fungibles is deployed as a single contract with settings of entire collection
  • ERC1155 allows each token ID to represent new configuration token type which may have its own metadata

Issues with other token standards

  • Redundant bytecodes : ERC-20 and ERC-721 require a separate contract to be deployed for each token type or collection.
  • Certain functionalities can be limited by separating each token contract into its own addresses
  • Blockchain games may require thousands of token types, and a new type.

ERC-1155 Interface


      interface ERC1155 /* is ERC165 */ {
        event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value);
        event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);
        event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
        event URI(string _value, uint256 indexed _id);
        function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external;
        function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external;
        function balanceOf(address _owner, uint256 _id) external view returns (uint256);
        function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
        function setApprovalForAll(address _operator, bool _approved) external;
        function isApprovedForAll(address _owner, address _operator) external view returns (bool);
    }
    /// type(I).interfaceId
    interface ERC165 {
        function supportsInterface(bytes4 interfaceID) external view returns (bool);
    }
    

ERC1155 NFT Contract

ERC1155 Required Interface

>
>
>

Examples of web3-eth

  • web3.eth.getBalance : balance of an address at a given block
  • web3.eth.signTransaction : sign a transaction
  • web3.eth.sendSignedTransaction : send a signed transaction to the Ethereum blockchain.

Examples of web3-shh

  • web3.shh.post : posts a whisper message to the network
  • web3.shh.subscribe : creates a subscription to incoming whisper messages

Examples of web3-bzz

  • web3.bzz.upload : upload files and folders to Swarm
  • web3.bzz.download : download files and folders from Swarm

Examples of web3-net

  • web3.*.net.getID : returns the network ID
  • web3.*.net.getPeerCount : returns the number of peers that the node is connected to

Examples of web3-utils

  • web3.utils.toWei : converts Ether to Wei
  • web3.utils.hexToNumberString : converts a hexadecimal value to a string
  • web3.utils.isAddress checks if a given string is a valid Ethereum address.
>
>

Examples of ethers.provider

  • ethers.providers.InfuraProvider : connect to the Infura hosted network of Ethereum nodes
  • ethers.provider.getBalance : Balance of an address or a block in the blockchain
  • ethers.provider.resolve : resolve an Ethereum Name Service (ENS) name passed in to an Ethereum address.

Examples of ethers.contract

  • ethers.ContractFactory.fromSolidity : creates a “factory” for deployment of a smart contract from compiler output of the Solidity compiler or from the Truffle generated JSON fileethers.Contract allows you to interact with a smart contract once it has been deployed.

Examples of ethers.utils

  • ethers.utils.getContractAddress : retrieves a smart contract address from the transaction used to deploy the smart contract
  • ethers.utils.computeAddress : computes an address by passing the function the public or private key associated with the address
  • ethers.utils.formatEther will format a passed in amount of Wei into a decimal string of Ether

Examples of ethers.wallet

  • ethers.wallet.createRandom : create a random new account.
  • ethers.wallet.sign : sign a transaction and returns the signed transaction as a hex string.
  • ethers.wallet.getBalance : balance of a wallet address.

Which library to use in my DApp?

  • Popularity of library
  • Maintenance of library
  • Team behind development of library
  • Tests in library
  • Number of downloads of library
  • Web performance of library
  • Quality of documentation
  • Licensing of library

Recommended Resources