# 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:

```javascript
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:

1. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `ApproveData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     to: 'spender_address',
     token_id: 'token_id',
     contract_address: 'contract_address',
   };
   const result = await erc721.approve(name, data);
   console.log(result);
   ```
2. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `BalanceOfResult`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     owner: 'account_address',
     contract_address: 'contract_address',
   };
   const result = await erc721.balanceOf(name, data);
   console.log(result);
   ```
3. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `GetApprovedData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     token_id: 'token_id',
     contract_address: 'contract_address',
   };
   const result = await erc721.getApproved(name, data);
   console.log(result);
   ```
4. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `IsApprovedForAllResult`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     owner: 'account_address',
     operator: 'operator_address',
     contract_address: 'contract_address',
   };
   const result = await erc721.isApprovedForAll(name, data);
   console.log(result);
   ```
5. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `NameData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     contract_address: 'contract_address',
   };
   const result = await erc721.name(name, data);
   console.log(result);
   ```
6. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `OwnerOfData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     token_id: 'token_id',
     contract_address: 'contract_address',
   };
   const result = await erc721.ownerOf(name, data);
   console.log(result);
   ```
7. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `SafeTransferFromResult`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     from: 'sender_address',
     to: 'recipient_address',
     token_id: 'token_id',
     contract_address: 'contract_address',
   };
   const result = await erc721.safeTransferFrom(name, data);
   console.log(result);
   ```
8. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `SetApprovalForAllResult`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     owner: 'account_address',
     operator: 'operator_address',
     approved: true,
     contract_address: 'contract_address',
   };
   const result = await erc721.setApprovalForAll(name, data);
   console.log(result);
   ```
9. `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 type `Erc721Request` that contains the necessary information to make the request.
   * `params` is an optional object of type `RequestParams` that can be used to customize the request.
   * Returns a promise that resolves to an object of type `SymbolData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     contract_address: 'contract_address',
   };
   const result = await erc721.symbol(name, data);
   console.log(result);
   ```
10. `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 type `Erc721Request` that contains the necessary information to make the request.
    * `params` is an optional object of type `RequestParams` that can be used to customize the request.
    * Returns a promise that resolves to an object of type `TokenUriData`.

    Example usage:

    ```javascript
    const name = 'my_token';
    const data = {
      token_id: 'token_id',
      contract_address: 'contract_address',
    };
    const result = await erc721.tokenUri(name, data);
    console.log(result);
    ```
11. `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 type `Erc721Request` that contains the necessary information to make the request.
    * `params` is an optional object of type `RequestParams` that can be used to customize the request.
    * Returns a promise that resolves to an object of type `TransferData`.

    Example usage:

    ```javascript
    const name = 'my_token';
    const data = {
      from: 'sender_address',
      to: 'recipient_address',
      token_id: 'token_id',
      contract_address: 'contract_address',
    };
    const result = await erc721.transfer(name, data);
    console.log(result);
    ```
12. `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 type `Erc721Request` that contains the necessary information to make the request.
    * `params` is an optional object of type `RequestParams` that can be used to customize the request.
    * Returns a promise that resolves to an object of type `TransferFromData`.

    Example usage:

    ```javascript
    const name = 'my_token';
    const data = {
      from: 'sender_address',
      to: 'recipient_address',
      token_id: 'token_id',
      contract_address: 'contract_address',
    };
    const result = await erc721.transferFrom(name, data);
    console.log(result);
    ```

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.usemoon.ai/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/erc721.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
