TokenERC1155

ERC-1155 standard compliant token contract, supporting minting and transferring of non-fungible tokens.

TokenERC1155 Contract

This contract implements the ERC-1155 standard for managing non-fungible tokens. It allows users to mint, transfer, and manage unique digital assets.

Features

  • Minting of new ERC-1155 tokens
  • Transferring tokens between accounts
  • Setting base URI for token metadata
  • Checking token balance for individual accounts
  • Batch minting and batch transferring

Usage

To use the TokenERC1155 contract, you need to first deploy it to a blockchain. Once deployed, you can interact with the contract through its functions.

Functions

Write Functions

  • mint(address to, uint256 id, uint256 amount, bytes memory data): Mints new tokens of a specific ID to a designated recipient.
  • mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data): Mints a batch of new tokens with different IDs to a recipient.
  • setURI(string memory newuri): Sets the base URI for fetching token metadata.

Read Functions

  • balanceOf(address owner, uint256 id): Retrieves the balance of a specific token ID for a given account.
  • balanceOfBatch(address[] memory owners, uint256[] memory ids): Retrieves the balance of multiple token IDs for multiple accounts.
  • uri(uint256 id): Returns the URI for a specific token ID.

Events

  • TransferSingle(address operator, address from, address to, uint256 id, uint256 value): Emitted when a single token is transferred.
  • TransferBatch(address operator, address from, address to, uint256[] memory ids, uint256[] memory values): Emitted when a batch of tokens are transferred.
  • ApprovalForAll(address owner, address operator, bool approved): Emitted when an operator is approved or revoked for an owner.

Implementation Details

The contract utilizes the OpenZeppelin ERC1155 implementation as a foundation, ensuring compatibility with the established standard.

Best Practices

  • Use a secure random number generator for minting unique token IDs.
  • Consider implementing access control mechanisms to limit minting and other actions.
  • Store token metadata off-chain for better scalability and cost efficiency.