ERC-721
The ERC721
class in the Eidolon.Unity SDK facilitates interaction with ERC-721 tokens on the Ethereum blockchain. Users can create an instance of the ERC721
class with a custom contract address to interact with a specific ERC-721 token.
Instantiating ERC721
Instantiate an ERC721
contract using one of the provided constructors:
Using ERC721
Now that we have our instance, let’s utilize it for a BalanceOf
call:
In this example, we create an instance of ERC721
with a custom contract address. Then, we use this instance to call methods like BalanceOf
, GetApproved
, IsApprovedForAll
, Name
, OwnerOf
, Symbol
, and TokenURI
to interact with the ERC-721 token.
ERC721
The ERC721
class provides methods for both reading and writing data to an ERC-721 contract on the Ethereum blockchain.
Read Methods
BalanceOf
Description
This method returns the balance of tokens owned by a specific Ethereum wallet address for an ERC-721 contract.
Example Code
Parameters
owner
(string): The Ethereum wallet address for which to retrieve the token balance.
Returns
BigInteger
: The balance of tokens owned by the specified wallet address.
GetApproved
Description
This method retrieves the approved address for a specific token.
Example Code
Parameters
tokenId
(BigInteger): The ID of the token.
Returns
string
: The address approved to manage the specified token.
IsApprovedForAll
Description
This method checks if an operator is approved to manage all 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 tokens of the owner; otherwise,false
.
Name
Description
This method retrieves the name of the ERC-721 token.
Example Code
Returns
string
: The name of the ERC-721 token.
OwnerOf
Description
This method retrieves the owner of a specific token.
Example Code
Parameters
tokenId
(BigInteger): The ID of the token.
Returns
string
: The Ethereum wallet address of the token owner.
Symbol
Description
This method retrieves the symbol of the ERC-721 token.
Example Code
Returns
string
: The symbol of the ERC-721 token.
TokenURI
Description
This method retrieves the Uniform Resource Identifier (URI) for a specific token.
Example Code
Parameters
tokenId
(BigInteger): The ID of the token.
Returns
string
: The URI for the specified token.
GetTokenMetadata
Description
This method retrieves the metadata for a specific ERC-721 token, including details such as name, description, and image URL.
Example Code
Parameters
tokenId
(BigInteger): The ID of the ERC-721 token.
Returns
Metadata
: An object containing metadata details.
Write Methods
Eidolon allows you to send transactions directly from an ERC721
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:
Approve
Description
This method approves an address to manage the specified token.
Example Code
Parameters
-
to
(string): The Ethereum wallet address of the recipient. -
tokenId
(BigInteger): The ID of the token. -
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 approval.
TransferFrom
Description
This method allows the spender to transfer a specified amount of 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
(BigInteger): The ID of the token.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 transfer from.
SafeTransferFrom
Description
This method safely transfers a specified amount of 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
(BigInteger): The ID of the token.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.
SafeTransferFromWithData
Description
This method safely transfers a specified amount of tokens from the owner’s address to the recipient’s address with additional data.
Example Code
Parameters
from
(string): The Ethereum wallet address of the owner.to
(string): The Ethereum wallet address of the recipient.tokenId
(BigInteger): The ID of the token.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 with data.
SetApprovalForAll
Description
This method sets or revokes approval for the operator to manage all 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.