# @moonup/moon-api

## @moonup/moon-api Package Documentation

The `@moonup/moon-api` package is a comprehensive library that provides a set of APIs for interacting with various blockchain networks and decentralized finance (DeFi) protocols. This package includes support for Ethereum, Bitcoin, Bitcoin Cash, Dogecoin, Litecoin, EOS, Solana, Cosmos, Tron, and more.

## **Installing Moon API:**

To use the Moon API package, first install it to a project:

#### To install Moon **API**:

{% tabs %}
{% tab title="npm" %}

```bash
npm install @moonup/moon-api
```

{% endtab %}

{% tab title="yarn" %}

```bash
yarn add @moonup/moon-api
```

{% endtab %}

{% tab title="pnpm" %}

```bash
pnpm add @moonup/moon-api
```

{% endtab %}
{% endtabs %}

### Usage

To use the `@moonup/moon-api` package, you'll first need to install it using a package manager like npm or Yarn. Once you've installed the package, you can import the classes and methods you need into your project.

Here's an example of how to use the `Accounts` class to create a new Ethereum account and transfer ETH:

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

// Initialize the HttpClient with your API base URL and security worker
const http = new HttpClient({
  baseUrl: 'https://beta.usemoon.ai',
  securityWorker: async (securityData) => {
    return {
      headers: {
        Authorization: `Bearer ${securityData.token}`,
      },
    };
  },
});

// Create an instance of the Accounts class
const accounts = new Accounts(http);

// Create a new Ethereum account
const createAccountData = await accounts.createAccount({ private_key: 'your_private_key' });
console.log('New account created:', createAccountData.address);

// Transfer ETH from the new account to another account
const transferEthData = await accounts.transferEth(createAccountData.name, {
  to: '0xAnotherAccountAddress',
  value: '1000000000000000000', // 1 ETH in wei
});
console.log('Transfer successful:', transferEthData.transactionHash);
```

This example demonstrates how to use the `Accounts` class to create a new Ethereum account and transfer ETH to another account. The `HttpClient` class is used to make HTTP requests to the API, and the `securityWorker` function is used to add an authorization header to the requests.

### Initialization

To use the `@moonup/moon-api` package, you'll first need to initialize an `HttpClient` object with your API base URL and security worker. The security worker is a function that returns the headers to be included in the API requests. In this case, it returns an authorization header with a bearer token.

Here's an example of how to initialize the `HttpClient` object:

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

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

In this example, the `baseUrl` property is set to the URL of the API, and the `securityWorker` property is set to a function that returns an authorization header with a bearer token. The `securityData` object is passed to the `securityWorker` function, which can be used to retrieve the bearer token.

Once you've initialized the `HttpClient` object, you can use it to create instances of the classes provided by the `@moonup/moon-api` package. For example:

```javascript
import { Accounts } from '@moonup/moon-api';

const accounts = new Accounts(http);
```

In this example, the `Accounts` class is imported from the `@moonup/moon-api` package, and an instance of the class is created using the `HttpClient` object.

## Classes

The package is organized into several files, each containing a class that provides methods for interacting with a specific blockchain network or DeFi protocol. The main files in the package are:

\
[Aave](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/aave.md)

Provides methods for interacting with the Aave decentralized lending protocol, including borrowing, lending, and repaying assets.

[Accounts](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/accounts.md)

Provides methods for creating and managing Ethereum accounts, deploying contracts, signing messages and transactions, and transferring ETH.

[Bitcoin](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/bitcoin.md)

Provide methods for creating and managing Bitcoin accounts, and signing transactions

[Bitcoin Cash](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/bitcoin-cash.md)

Provide methods for creating and managing Bitcoin Cash accounts, and signing transactions

[ConveyorFinance](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/conveyorfinance.md)

Provide methods for interacting with the ConveyorFinance decentralized exchange (DEX) protocols, including swapping tokens and checking prices

[Cosmos](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/cosmos.md)

Provide methods for interacting with the Cosmos  blockchain networks, including creating and managing accounts, and signing transactions.

[Dogecoin](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/dogecoin.md)

Provide methods for creating and managing Dogecoin accounts, and signing transactions

[Ens](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/ens.md)

Provides methods for interacting with the Ethereum Name Service (ENS), including registering and resolving domain names.

[EOS](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/eos.md)

Provide methods for interacting with the EOS blockchain networks, including creating and managing accounts, and signing transactions.

[Erc20](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/erc20.md)

Provide methods for interacting with Ethereum-based tokens, including transferring tokens, checking balances, and approving contracts.

[Erc721](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/erc721.md)

Provide methods for interacting with Ethereum-based tokens, including transferring tokens, checking balances, and approving contracts.

[Erc1155](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/erc1155.md)

Provide methods for interacting with Ethereum-based tokens, including transferring tokens, checking balances, and approving contracts.

[Litecoin](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/litecoin.md)

Provide methods for creating and managing Litecoin accounts, and signing transactions

[OneInch](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/oneinch.md)

Provide methods for interacting with the 1inch decentralized exchange (DEX) protocols, including swapping tokens and checking prices

[OnRamper](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/onramper.md)

Provides methods for interacting with the Onramper fiat onramp service, allowing users to buy cryptocurrencies with fiat currency.

[Ripple](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/ripple.md)

Provides methods for interacting with the Ripple blockchain network, including creating and managing accounts, and sending and receiving payments.

[Solana](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/solana.md)

Provides methods for interacting with the Solana blockchain network, including creating and managing accounts, and sending and receiving tokens.

[Tron](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/tron.md)

Provides methods for interacting with the TRON blockchain network, including creating and managing accounts, and sending and receiving tokens.

[Uniswap](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/uniswap.md)

Provide methods for interacting with the Uniswap decentralized exchange (DEX) protocols, including swapping tokens and checking prices

[Yearn](/additional-moon-packages-7ca327c0bb2846d88b8ba5bc6caeaead/moonup-moon-api/yearn.md)

Provides methods for interacting with the Yearn decentralized finance (DeFi) protocol, including depositing, withdrawing, and earning yield on assets.

Overall, the `@moonup/moon-api` package is a powerful and flexible library that provides a wide range of APIs for interacting with various blockchain networks and DeFi protocols. Whether you're building a simple wallet application or a complex decentralized finance platform, this package has the tools you need to get the job done.


---

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