Erc721
The Erc721
class from the @moonup/moon-api
package provides methods to interact with ERC-721 tokens.
Initialization
To use the Erc721
class, you need to create an instance of it by passing an instance of the HttpClient
class to its constructor. The HttpClient
class is also part of the @moonup/moon-api
package and provides a convenient way to make HTTP requests.
Here's an example of how to create an instance of the Erc721
class:
Methods
The Erc721
class provides the following methods:
approve(name: string, data: Erc721Request, params?: RequestParams): Promise<ApproveData>
Approves a spender to transfer a specific token on behalf of the owner.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
ApproveData
.
Example usage:
balanceOf(name: string, data: Erc721Request, params?: RequestParams): Promise<BalanceOfResult>
Retrieves the balance of a specific account for a given ERC-721 token.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
BalanceOfResult
.
Example usage:
getApproved(name: string, data: Erc721Request, params?: RequestParams): Promise<GetApprovedData>
Retrieves the address of the spender that is approved to transfer a specific token.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
GetApprovedData
.
Example usage:
isApprovedForAll(name: string, data: Erc721Request, params?: RequestParams): Promise<IsApprovedForAllResult>
Checks if an operator is approved to transfer all tokens of a specific owner.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
IsApprovedForAllResult
.
Example usage:
name(name: string, data: Erc721Request, params?: RequestParams): Promise<NameData>
Retrieves the name of a given ERC-721 token.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
NameData
.
Example usage:
ownerOf(name: string, data: Erc721Request, params?: RequestParams): Promise<OwnerOfData>
Retrieves the owner of a specific token.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
OwnerOfData
.
Example usage:
safeTransferFrom(name: string, data: Erc721Request, params?: RequestParams): Promise<SafeTransferFromResult>
Transfers a specific token from one account to another.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
SafeTransferFromResult
.
Example usage:
setApprovalForAll(name: string, data: Erc721Request, params?: RequestParams): Promise<SetApprovalForAllResult>
Approves or revokes an operator to transfer all tokens of a specific owner.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
SetApprovalForAllResult
.
Example usage:
symbol(name: string, data: Erc721Request, params?: RequestParams): Promise<SymbolData>
Retrieves the symbol of a given ERC-721 token.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
SymbolData
.
Example usage:
tokenUri(name: string, data: Erc721Request, params?: RequestParams): Promise<TokenUriData>
Retrieves the URI of a specific token.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
TokenUriData
.
Example usage:
transfer(name: string, data: Erc721Request, params?: RequestParams): Promise<TransferData>
Transfers a specific token from the sender's account to a recipient's account.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
TransferData
.
Example usage:
transferFrom(name: string, data: Erc721Request, params?: RequestParams): Promise<TransferFromData>
Transfers a specific token from a sender's account to a recipient's account on behalf of the sender.
name
is a string that represents the name of the ERC-721 token.data
is an object of typeErc721Request
that contains the necessary information to make the request.params
is an optional object of typeRequestParams
that can be used to customize the request.Returns a promise that resolves to an object of type
TransferFromData
.
Example usage:
These methods can be used to perform various operations on ERC-721 tokens, such as checking token balances, approving spenders, transferring tokens, and more. The Erc721
class is a part of the @moonup/moon-api
package, which provides a convenient way to interact with the Moon API.
The contract_address
and token_id
properties are required for most of the Erc721
class methods, as they are used to identify the specific ERC-721 token contract and token with which to interact. Without the contract_address
and token_id
properties, the method may not be able to correctly identify the token contract and token and may return incorrect results.
Last updated