Skip to main content

How to get current price by token address

Prerequisites

Before getting started, make sure you have the following ready:

  • Node v.14+
  • NPM

Step 1: Setup Blocklens

First register your Blocklens account and get your Blocklens API Key.

Once you have your Blocklens API Key, install the Blocklens SDK in your project.

npm i blocklens-sdk

Step 2: Get current price by token address

In order to get current price by token address, Blocklens provides you a getCurrentPriceByTokenAddress endpoint to do so.

Here you'll need a parameter: address.

Once you've obtained the address, you can copy the following code:

import Blocklens from "blocklens-sdk";

const blocklens = new Blocklens();
blocklens.init({ apiKey: "YOUR_API_KEY" });

const runApis = async () => {
const response = await blocklens.ETH_MAINNET.getCurrentPriceByTokenAddress("0x6339e5E072086621540D0362C4e3Cea0d643E114");
console.log(response);
};

runApis();

Step 3: Run the script

ts-node index.ts

In your terminal, you should see the following JSON response with the data: In your terminal, you should see the following JSON response with the data blocks:

{
"price": 2245.9016604813505,
"token_address": "0x0000000000000000000000000000000000000000",
"symbol": "ETH",
"timestamp": 1701694127,
"date": "2023-12-04 12:48:47.0"
}

Congratulations 🥳 you just found the get current price by token address on multiple chains with only a few lines of code using the Blocklens Wallet API!

API Reference

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

Support

If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.