> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get the price of a token

ERC20 tokens are one of the most popular types of cryptocurrencies in the market. These tokens are built on the Ethereum blockchain and are used for a variety of purposes, ranging from utility tokens for decentralized applications to security tokens for fractional ownership of assets.

As an investor or trader, it is important to keep track of the price of ERC20 tokens to make informed decisions about buying, selling or holding them. Fortunately, Chainbase provides a direct API [Get token price](/api-reference/web3-api/token/market-data/get-token-price) to get the price of different ERC20 tokens.

## Overview - Tools you need to work with Chainbase

1. A free account at [Chainbase](https://www.chainbase.com) with an API key.
2. An IDE. Our examples are shown in JavaScript, you can use [VS Code](https://code.visualstudio.com/) as your IDE for example.
3. A token address as your input.

## Step 1: Set up a free account at Chainbase

To better leverage the ability that Chainbase provides, you can register [here](http://www.chainbase.com/register) for a free account and access to different APIs and data cloud.

After logging into Chainbase, visit the [dashboard](https://console.chainbase.com/) to get an overview. Create a new project in the console and get an API key.

![](https://files.readme.io/a219134-image.png)

## Step 2: Write script using Chainbase API

1. Using `fetch` in JavaScript.

```jsx theme={null}
network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; // Take USDT as an example.

fetch(`https://api.chainbase.online/v1/token/price?chain_id=${network_id}&contract_address=${token_addr}`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));
```

2. Using `axios` in JavaScript. You need to install `axios` using `npm install axios --save` in the terminal first.

```jsx theme={null}
network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; // Take USDT as an example.

const axios = require('axios');
const options = {
    url: `https://api.chainbase.online/v1/token/price?chain_id=${network_id}&contract_address=${token_addr}`,
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
};
axios(options)
    .then(response => console.log(response.data.data))
    .catch(error => console.log(error));
```

## Step 3: Print the token price

Chainbase API [Get token price](/api-reference/web3-api/token/market-data/get-token-price) takes the chain id and the contract address of a certain ERC20 token as parameters, and returns the price of that token.

To get data printed, run command `node <filename>.js` in the terminal. In this case, the return data looks as follows. Note that `updated_at` indicates the GMT time when you query the data, which may vary accordingly.

```json theme={null}
{
  price: 1.001497299920505,
  symbol: 'usd',
  source: 'coinmarketcap',
  updated_at: '2023-03-21T19:37:49.249213Z'
}
```

## API Reference

If you want to know more details on the endpoint and optional parameters, check out:

* [Get token price](/api-reference/web3-api/token/market-data/get-token-price)

## Support

If you meet any trouble following the tutorial, feel free to reach out to us in our [Discord](https://chainbase.com/discord) to get 24/7 community support.
