> For the complete documentation index, see [llms.txt](https://docs.usemoon.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.usemoon.ai/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/erc1155.md).

# Erc1155

The `Erc1155` class from the `@moonup/moon-api` package provides methods to interact with ERC-1155 tokens.

### Initialization

To use the `Erc1155` 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 `Erc1155` class:

```javascript
import { HttpClient, Erc1155 } from '@moonup/moon-api';

const http = new HttpClient({
  baseUrl: 'https://beta.usemoon.ai',
  securityWorker: async (securityData) => {
    return {
      headers: {
        Authorization: `Bearer ${securityData.token}`,
      },
    };
  },
});

const erc1155 = new Erc1155(http);
```

### Methods

The `Erc1155` class provides the following methods:

1. `balanceOf(name: string, data: Erc1155Request, params?: RequestParams): Promise<BalanceOfData>`

   * Retrieves the balance of a specific account for a given ERC-1155 token.
   * `name` is a string that represents the name of the ERC-1155 token.
   * `data` is an object of type `Erc1155Request` 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 `BalanceOfData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     account: 'account_address',
     id: 'token_id',
     contract_address: 'contract_address',
   };
   const result = await erc1155.balanceOf(name, data);
   console.log(result);
   ```
2. `balanceOfBatch(name: string, data: Erc1155Request, params?: RequestParams): Promise<BalanceOfBatchData>`

   * Retrieves the balance of multiple accounts for multiple ERC-1155 tokens.
   * `name` is a string that represents the name of the ERC-1155 token.
   * `data` is an object of type `Erc1155Request` 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 `BalanceOfBatchData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     accounts: ['account1_address', 'account2_address'],
     ids: ['token1_id', 'token2_id'],
     contract_address: 'contract_address',
   };
   const result = await erc1155.balanceOfBatch(name, data);
   console.log(result);
   ```
3. `isApprovedForAll(name: string, data: Erc1155Request, params?: RequestParams): Promise<IsApprovedForAllData>`

   * 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-1155 token.
   * `data` is an object of type `Erc1155Request` 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 `IsApprovedForAllData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     account: 'account_address',
     operator: 'operator_address',
     contract_address: 'contract_address',
   };
   const result = await erc1155.isApprovedForAll(name, data);
   console.log(result);
   ```
4. `safeBatchTransferFrom(name: string, data: Erc1155Request, params?: RequestParams): Promise<SafeBatchTransferFromData>`

   * Transfers multiple tokens from one account to another.
   * `name` is a string that represents the name of the ERC-1155 token.
   * `data` is an object of type `Erc1155Request` 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 `SafeBatchTransferFromData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     from: 'sender_address',
     to: 'recipient_address',
     ids: ['token1_id', 'token2_id'],
     amounts: ['amount1', 'amount2'],
     contract_address: 'contract_address',
   };
   const result = await erc1155.safeBatchTransferFrom(name, data);
   console.log(result);
   ```
5. `safeTransferFrom(name: string, data: Erc1155Request, params?: RequestParams): Promise<SafeTransferFromData>`

   * Transfers a specific token from one account to another.
   * `name` is a string that represents the name of the ERC-1155 token.
   * `data` is an object of type `Erc1155Request` 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 `SafeTransferFromData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     from: 'sender_address',
     to: 'recipient_address',
     id: 'token_id',
     amount: 'amount',
     contract_address: 'contract_address',
   };
   const result = await erc1155.safeTransferFrom(name, data);
   console.log(result);
   ```
6. `setApprovalForAll(name: string, data: Erc1155Request, params?: RequestParams): Promise<SetApprovalForAllData>`

   * Approves or revokes an operator to transfer all tokens of a specific owner.
   * `name` is a string that represents the name of the ERC-1155 token.
   * `data` is an object of type `Erc1155Request` 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 `SetApprovalForAllData`.

   Example usage:

   ```javascript
   const name = 'my_token';
   const data = {
     account: 'account_address',
     operator: 'operator_address',
     approved: true,
     contract_address: 'contract_address',
   };
   const result = await erc1155.setApprovalForAll(name, data);
   console.log(result);
   ```

These methods can be used to perform various operations on ERC-1155 tokens, such as checking token balances, approving operators, transferring tokens, and more. The `Erc1155` 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 `Erc1155` class methods, as they are used to identify the specific ERC-1155 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
