Links

erc20_tokenPrice

Get current/historical price data.
Through erc20_tokenPrice, you can fetch the data of token price of that token collection, token0 and token1 are necessary. Statistics like timestamp, token name and token swap price will be returned.
Supported on Ethereum and BNB Chain.

Parameters

Object - An object with the following fields (required):
  • token0(hex string, required) - address of a token that you want to query.
  • token1(hex string, required) - address of the other token you want to query.
  • blockNumber(integer number, optional) - specify the blockNumber for snapshot query (default latest). BlockVision can not only support users to query the current position, but also support users to query the historical information at any time.

Returns

Object - An object with the following fields:
  • id(integer number) - json-rpc id.
  • jsonrpc(string) - json-rpc version.
  • result(object) - an object with the following fields:
    • timestamp - price time.
    • token0(hex string) - address of the token0.
    • token0Name(string) - name of the token0.
    • token0Price(string) - the amount of token0 needed to swap 1 token1.
    • token1(hex string) - address of the token1.
    • token1Name(string) - name of the token1.
    • token1Price(string) - the amount of token1 needed to swap 1 token0.
    • blockNumbers(array of integer number) - where the prices are calculated from.
Notice: You don't have to worry about the order of token0/token1, our API will change the order according to your parameters.

Example

Request

curl
TypeScript
curl https://api.blockvision.org/v1/<api key> \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 0,
"method": "erc20_tokenPrice",
"params": {
"blockNumber": 0,
"token0": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"token1": "0xdAC17F958D2ee523a2206206994597C13D831ec7"
}
}'
import { BlockVisionProvider, BvNetwork } from 'blockvision.js'
​
// Optional parameters, but default to eth-mainnet and default api-key.
const bv = new BlockVisionProvider(BvNetwork.ETH_MAINNET)
​
// Access the BlockVision FT API
bv.getERC20TokenPrice({
blockNumber: 0,
token0: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
token1: '0xdAC17F958D2ee523a2206206994597C13D831ec7'
}).then(console.log)

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"token0": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"token1": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"token0Name": "Wrapped Ether",
"token1Name": "Tether USD",
"token0Price": "1968",
"token1Price": " 1"
}
}