erc20_tokenPrice
The Price API can help you easily fetch current/historical price data.
You can specify the block number and two contract addresses, which are to swap. Then you can obtain the data of token price of that token collection. 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):
  • blockNumber(integer number, required) - 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.
  • 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.

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 numbers) - 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 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"
}
}'

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"token0": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"token1": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
"token0Name": "Wrapped Ether",
"token1Name": "Tether USD",
"token0Price": "1968",
"token1Price": " 1"
}
}
Copy link
Outline
Parameters
Returns
Example
Request
Result