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:
import { HttpClient, Erc721 } from '@moonup/moon-api';
const http = new HttpClient({
baseUrl: 'https://beta.usemoon.ai',
securityWorker: async (securityData) => {
return {
headers: {
Authorization: `Bearer ${securityData.token}`,
},
};
},
});
const erc721 = new Erc721(http);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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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.
nameis a string that represents the name of the ERC-721 token.datais an object of typeErc721Requestthat contains the necessary information to make the request.paramsis an optional object of typeRequestParamsthat 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