# Token API

### Endpoint Overview

TokenInfo.AI provides endpoints for creating Solana tokens and retrieving the estimated gas fee required for token creation. These endpoints are essential for users who want to create new tokens on the Solana network and understand the associated costs.

#### Endpoints

1. **Create Solana Token**
2. **Get Estimated Gas Fee**

### Create Solana Token

#### Endpoint

**POST** `/token/create`

#### Request Parameters

**Body Parameters**

* **userAddress**:
  * **Type**: String
  * **Description**: The address of the user creating the token. This parameter is required.
* **payer**:
  * **Type**: String
  * **Description**: The payer's secret key. This parameter is required.
* **network**:
  * **Type**: String
  * **Description**: The network on which to create the token. This parameter is required.
* **tax**:
  * **Type**: Number
  * **Description**: The tax to be applied on the token. This parameter is required.
* **name**:
  * **Type**: String
  * **Description**: The name of the token. This parameter is required.
* **symbol**:
  * **Type**: String
  * **Description**: The symbol of the token. This parameter is required.
* **decimals**:
  * **Type**: Number
  * **Description**: The number of decimal places for the token. This parameter is required.
* **supply**:
  * **Type**: Number
  * **Description**: The initial supply of the token. This parameter is required.
* **canMint**:
  * **Type**: Boolean
  * **Description**: Whether the token can be minted. This parameter is required.

**File Parameter**

* **photo**:
  * **Type**: File (image)
  * **Description**: The file containing the token's logo. This parameter is required.

#### Request Example

Here is an example of how to structure the request:

```http
POST /token/create
Content-Type: multipart/form-data

{
  "userAddress": "0xYourUserAddress",
  "payer": "YourPayerSecretKey",
  "network": "mainnet-beta",
  "tax": 2,
  "name": "TokenName",
  "symbol": "SYM",
  "decimals": 9,
  "supply": 1000000,
  "canMint": true,
  "photo": [Image File]
}
```

#### Response

The response from the endpoint will vary depending on the success or failure of the request.

**Success Response**

* **Status Code**: `200 OK`
* **Response Body**:

```json
{
  "status": true,
  "token": "0xTokenAddress",
  "signature":"0xSignature"
}
```

**Error Responses**

1. **Missing Parameters**

   * **Status Code**: `400 Bad Request`
   * **Response Body**:

   ```json
   {
     "error": "Missing parameters",
     "expecting": {
       "userAddress": "0xYourUserAddress",
       "payer": "YourPayerSecretKey",
       "network": "mainnet-beta",
       "tax": 2,
       "name": "TokenName",
       "symbol": "SYM",
       "decimals": 9,
       "supply": 1000000,
       "canMint": true,
       "logo": "Image File"
     }
   }
   ```
2. **Invalid File Type**

   * **Status Code**: `400 Bad Request`
   * **Response Body**:

   ```json
   {
     "error": "Wrong file type",
     "expecting": "image",
     "sent": "application/json"
   }
   ```
3. **File Too Large**

   * **Status Code**: `400 Bad Request`
   * **Response Body**:

   ```json
   {
     "error": "File size exceeds the maximum limit",
     "expecting": "2MB",
     "sent": "5MB"
   }
   ```
4. **Internal Server Error**

   * **Status Code**: `500 Internal Server Error`
   * **Response Body**:

   ```json
   {
     "error": "An internal server error occurred"
   }
   ```

### Get Estimated Gas Fee

#### Endpoint

**GET** `/token/gasfee`

#### Request Parameters

This endpoint does not require any parameters.

#### Request Example

Here is an example of how to structure the request:

```http
GET /token/gasfee
```

#### Response

The response from the endpoint will be in JSON format, providing the estimated gas fee in SOL.

**Success Response**

* **Status Code**: `200 OK`
* **Response Body**:

```json
{
  "status": true,
  "gasfee": 0.002 // Estimated gas fee in SOL
}
```

## Token Metadata and Market Metadata Endpoints Documentation

### Overview

These endpoints allow you to retrieve metadata and market data for specific tokens on various blockchain networks. You can fetch information like the token's name, symbol, decimal places, total supply, and market-related data such as current price and market capitalization.

#### Endpoints

* **POST** `/token/:chain/metadata` - Retrieve token metadata.
* **POST** `/token/:chain/market` - Retrieve token market metadata.

***

### 1. Get Token Metadata

#### Endpoint

**POST** `/token/:chain/metadata`

#### Description

This endpoint retrieves the metadata for tokens given their addresses. Metadata includes the token's name, symbol, decimals, logo, and total supply.

#### Request Parameters

**URL Parameters**

* **chain**:
  * **Type**: Number
  * **Description**: The blockchain network chain ID. Supported chains:
    * `1`: Ethereum Mainnet (default)
    * `56`: Binance Smart Chain
    * `97`: Binance Smart Chain Testnet
    * `800`: Solana Mainnet
    * `137`: Polygon Mainnet
    * `8453`: Base Mainnet
    * `42161`: Arbitrum Mainnet

**Body Parameters**

* **addresses**:
  * **Type**: Array of Strings
  * **Description**: An array of token contract addresses.
  * **Example**: `["0xTokenAddress1", "0xTokenAddress2"]`

#### Response

**Success Response**

* **Status Code**: `200 OK`
* **Response Body**:

```json
{
  "status": true,
  "metas": {
    "0xTokenAddress1": {
      "address": "0xTokenAddress1",
      "name": {
        "short": "TokenName",
        "long": "Token Name Long"
      },
      "symbol": "TKN",
      "decimal": 18,
      "logo": {
        "small": "https://example.com/small_logo.png",
        "big": "https://example.com/big_logo.png"
      },
      "totalSupply": 1000000
    }
  }
}
```

**Error Responses**

1. **Missing Parameters**

   * **Status Code**: `400 Bad Request`
   * **Response Body**:

   ```json
   {
     "error": "Addresses must be an array"
   }
   ```
2. **Internal Server Error**

   * **Status Code**: `500 Internal Server Error`
   * **Response Body**:

   ```json
   {
     "error": "An internal server error occurred"
   }
   ```

#### Example Request

```http
POST /token/1/metadata
Content-Type: application/json

{
  "addresses": ["0xTokenAddress1", "0xTokenAddress2"]
}
```

#### Example Response

```json
{
  "status": true,
  "metas": {
    "0xTokenAddress1": {
      "address": "0xTokenAddress1",
      "name": {
        "short": "TokenName",
        "long": "Token Name Long"
      },
      "symbol": "TKN",
      "decimal": 18,
      "logo": {
        "small": "https://example.com/small_logo.png",
        "big": "https://example.com/big_logo.png"
      },
      "totalSupply": 1000000
    }
  }
}
```

***

### 2. Get Token Market Metadata

#### Endpoint

**POST** `/token/:chain/market`

#### Description

This endpoint retrieves market-related metadata for tokens, such as the current price, market capitalization, and total volume.

#### Request Parameters

**URL Parameters**

* **chain**:
  * **Type**: Number
  * **Description**: The blockchain network chain ID. Supported chains:
    * `1`: Ethereum Mainnet (default)
    * `56`: Binance Smart Chain
    * `97`: Binance Smart Chain Testnet
    * `800`: Solana Mainnet
    * `137`: Polygon Mainnet
    * `8453`: Base Mainnet
    * `42161`: Arbitrum Mainnet

**Body Parameters**

* **addresses**:
  * **Type**: Array of Strings
  * **Description**: An array of token contract addresses.
  * **Example**: `["0xTokenAddress1", "0xTokenAddress2"]`

#### Response

**Success Response**

* **Status Code**: `200 OK`
* **Response Body**:

```json
{
  "status": true,
  "metas": {
    "0xTokenAddress1": {
      "address": "0xTokenAddress1",
      "name": {
        "short": "TokenName",
        "long": "Token Name Long"
      },
      "symbol": "TKN",
      "decimal": 18,
      "logo": {
        "small": "https://example.com/small_logo.png",
        "big": "https://example.com/big_logo.png"
      },
      "totalSupply": 1000000,
      "description": "Token description",
      "market_data": {
        "current_price": 123.45,
        "market_cap": 1000000,
        "total_volume": 50000
      },
      "platforms": {
        "ethereum": "0xTokenAddress1"
      }
    }
  }
}
```

**Error Responses**

1. **Missing Parameters**

   * **Status Code**: `400 Bad Request`
   * **Response Body**:

   ```json
   {
     "error": "Addresses must be an array"
   }
   ```
2. **Internal Server Error**

   * **Status Code**: `500 Internal Server Error`
   * **Response Body**:

   ```json
   {
     "error": "An internal server error occurred"
   }
   ```

#### Example Request

```http
POST /token/1/market
Content-Type: application/json

{
  "addresses": ["0xTokenAddress1", "0xTokenAddress2"]
}
```

#### Example Response

```json
{
  "status": true,
  "metas": {
    "0xTokenAddress1": {
      "address": "0xTokenAddress1",
      "name": {
        "short": "TokenName",
        "long": "Token Name Long"
      },
      "symbol": "TKN",
      "decimal": 18,
      "logo": {
        "small": "https://example.com/small_logo.png",
        "big": "https://example.com/big_logo.png"
      },
      "totalSupply": 1000000,
      "description": "Token description",
      "market_data": {
        "current_price": 123.45,
        "market_cap": 1000000,
        "total_volume": 50000
      },
      "platforms": {
        "ethereum": "0xTokenAddress1"
      }
    }
  }
}
```

***

#### Notes

* Both endpoints support multiple chains, and the results depend on the specified chain.
* The response is tailored to include all relevant token metadata and market information.
* Only the first 20 addresses provided will be processed to ensure efficiency.

## Get Token List for a Specific Chain

### Overview

This endpoint retrieves a list of the tokens for a specific blockchain network. The response includes detailed information about each token, including its name, symbol, decimal places, logos, total supply, market data, and more. The maximum number of tokens returned is 50.

#### Endpoint

**GET** `/token/:chain/list`

***

### Description

This endpoint allows you to get a detailed list of up to 50 top tokens available on a specified blockchain network. It uses the CoinGecko API to fetch the most popular tokens and their associated metadata.

### Request Parameters

#### URL Parameters

* **chain**:
  * **Type**: Number
  * **Description**: The blockchain network chain ID. Supported chains:
    * `1`: Ethereum Mainnet (default)
    * `56`: Binance Smart Chain
    * `97`: Binance Smart Chain Testnet
    * `800`: Solana Mainnet
    * `137`: Polygon Mainnet
    * `8453`: Base Mainnet
    * `42161`: Arbitrum Mainnet
  * **Required**: Yes

### Response

#### Success Response

* **Status Code**: `200 OK`
* **Response Body**:

```json
{
  "status": true,
  "data": [
    {
      "address": "0xTokenAddress1",
      "name": {
        "short": "TokenName",
        "long": "Token Name Long"
      },
      "symbol": "TKN",
      "decimal": 18,
      "logo": {
        "small": "https://example.com/small_logo.png",
        "big": "https://example.com/big_logo.png"
      },
      "totalSupply": 1000000,
      "description": "This is a sample token description.",
      "market_data": {
        "current_price": 123.45,
        "market_cap": 1000000,
        "total_volume": 50000
      },
      "platforms": {
        "ethereum": "0xTokenAddress1"
      }
    },
    // more tokens...
  ]
}
```

#### Error Responses

1. **Unsupported Chain**

   * **Status Code**: `400 Bad Request`
   * **Response Body**:

   ```json
   {
     "status": false,
     "msg": "Unsupported chain ID"
   }
   ```
2. **Fetch Error**

   * **Status Code**: `500 Internal Server Error`
   * **Response Body**:

   ```json
   {
     "status": false,
     "msg": "Failed to fetch coin list: [Error Description]"
   }
   ```
3. **Internal Server Error**

   * **Status Code**: `500 Internal Server Error`
   * **Response Body**:

   ```json
   {
     "status": false,
     "msg": "An unexpected error occurred while fetching coins."
   }
   ```

### Example Request

```http
GET /token/1/list
```

### Example Response

```json
{
  "status": true,
  "data": [
    {
      "address": "0xTokenAddress1",
      "name": {
        "short": "TokenName",
        "long": "Token Name Long"
      },
      "symbol": "TKN",
      "decimal": 18,
      "logo": {
        "small": "https://example.com/small_logo.png",
        "big": "https://example.com/big_logo.png"
      },
      "totalSupply": 1000000,
      "description": "This is a sample token description.",
      "market_data": {
        "current_price": 123.45,
        "market_cap": 1000000,
        "total_volume": 50000
      },
      "platforms": {
        "ethereum": "0xTokenAddress1"
      }
    }
    // more tokens...
  ]
}
```

### Notes

* The maximum number of tokens returned is 50 to limit the number of API calls.
* The response includes detailed information for each token, including metadata and market data.
* The chain parameter must be a valid and supported chain ID. If an unsupported chain is requested, an error response will be returned.

By utilizing the Token Endpoints, users can efficiently create new tokens on the Solana network and understand the associated costs, enabling better management of their crypto projects within the TokenInfo.AI platform.


---

# 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://coat.gitbook.io/tokeninfo.ai/token-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.
