ERC-1155
The ERC1155
class in the Eidolon.Unity SDK facilitates interaction with ERC-1155 tokens on the Ethereum blockchain. Users can create an instance of the ERC1155
class with a custom contract address to interact with a specific ERC-1155 token.
Instantiating ERC1155
Instantiate an ERC1155
contract using one of the provided constructors:
Using ERC1155
Now that we have our instance, let’s utilize it for a BalanceOf
call:
In this example, we create an instance of ERC1155
with a custom contract address. Then, we use this instance to call methods like BalanceOf
, BalanceOfBatch
, IsApprovedForAll
, and TokenURI
to interact with the ERC-1155 token.
ERC1155
The ERC1155
class provides methods for both reading and writing data to an ERC-1155 contract on the Ethereum blockchain.
Read Methods
BalanceOf
Description
This method returns the balance of a specific ERC-1155 token owned by a given Ethereum wallet address.
Example Code
Parameters
owner
(string): The Ethereum wallet address of the owner.tokenId
(BigInteger): The ID of the ERC-1155 token.
Returns
BigInteger
: The balance of the specified ERC-1155 token owned by the specified wallet address.
BalanceOfBatch
Description
This method returns the balances of multiple ERC-1155 tokens owned by multiple Ethereum wallet addresses.
Example Code
Parameters
owners
(string[]): An array of Ethereum wallet addresses.tokenIds
(BigInteger[]): An array of ERC-1155 token IDs.
Returns
BigInteger[]
: An array of balances corresponding to the specified ERC-1155 tokens and wallet addresses.
IsApprovedForAll
Description
This method checks if an operator is approved to manage all ERC-1155 tokens on behalf of the owner.
Example Code
Parameters
owner
(string): The Ethereum wallet address of the owner.operatorAddress
(string): The Ethereum wallet address of the operator.
Returns
bool
:true
if the operator is approved for all ERC-1155 tokens of the owner; otherwise,false
.
TokenURI
Description
This method retrieves the Uniform Resource Identifier (URI) for a specific ERC-1155 token.
Example Code
Parameters
tokenId
(BigInteger): The ID of the ERC-1155 token.
Returns
string
: The URI for the specified ERC-1155 token.
GetTokenMetadata
Description
This method retrieves the metadata for a specific ERC-1155 token, including details such as name, description, and image URL.
Example Code
Parameters
tokenId
(BigInteger): The ID of the ERC-1155 token.
Returns
Metadata
: An object containing metadata details.
Write Methods
Eidolon allows you to send transactions directly from an ERC1155
instance through the use of a Wallet
. You can either create a new Wallet
or use an existing one.
Example Code
Let’s have a look at the built-in functions available to us:
SetApprovalForAll
Description
This method sets or revokes approval for an operator to manage all ERC-1155 tokens on behalf of the owner.
Example Code
Parameters
operatorAddress
(string): The Ethereum wallet address of the operator.approved
(bool):true
to set approval,false
to revoke.gas
(string, optional): The gas limit for the transaction.gasPrice
(string, optional): The gas price for the transaction.
Returns
string
: The transaction hash of the set approval for
all.
SafeTransferFrom
Description
This method safely transfers a specified amount of ERC-1155 tokens from the owner’s address to the recipient’s address.
Example Code
Parameters
from
(string): The Ethereum wallet address of the owner.to
(string): The Ethereum wallet address of the recipient.tokenId
(uint): The ID of the ERC-1155 token.amount
(uint): The amount of tokens to transfer.data
(byte[]): Additional data for the transaction.gas
(string, optional): The gas limit for the transaction.gasPrice
(string, optional): The gas price for the transaction.
Returns
string
: The transaction hash of the safe transfer.
SafeBatchTransferFrom
Description
This method safely transfers specified amounts of multiple ERC-1155 tokens from the owner’s address to the recipient’s address.
Example Code
Parameters
from
(string): The Ethereum wallet address of the owner.to
(string): The Ethereum wallet address of the recipient.tokenIds
(uint[]): The array of ERC-1155 token IDs.amounts
(uint[]): The array of amounts corresponding to each token ID.data
(byte[]): Additional data for the transaction.gas
(string, optional): The gas limit for the transaction.gasPrice
(string, optional): The gas price for the transaction.
Returns
string
: The transaction hash of the safe batch transfer.