Skip to main content
POST
/
rpc
/
Trails
/
GetTokenPrices
GetTokenPrices will return the live prices for a list of tokens.
curl --request POST \
  --url https://trails-api.sequence.app/rpc/Trails/GetTokenPrices \
  --header 'Content-Type: application/json' \
  --data '
{
  "tokens": [
    {
      "chainId": 123,
      "tokenAddress": "<string>",
      "tokenSymbol": "<string>"
    }
  ]
}
'
import requests

url = "https://trails-api.sequence.app/rpc/Trails/GetTokenPrices"

payload = { "tokens": [
{
"chainId": 123,
"tokenAddress": "<string>",
"tokenSymbol": "<string>"
}
] }
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({tokens: [{chainId: 123, tokenAddress: '<string>', tokenSymbol: '<string>'}]})
};

fetch('https://trails-api.sequence.app/rpc/Trails/GetTokenPrices', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://trails-api.sequence.app/rpc/Trails/GetTokenPrices",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'tokens' => [
[
'chainId' => 123,
'tokenAddress' => '<string>',
'tokenSymbol' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://trails-api.sequence.app/rpc/Trails/GetTokenPrices"

payload := strings.NewReader("{\n \"tokens\": [\n {\n \"chainId\": 123,\n \"tokenAddress\": \"<string>\",\n \"tokenSymbol\": \"<string>\"\n }\n ]\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://trails-api.sequence.app/rpc/Trails/GetTokenPrices")
.header("Content-Type", "application/json")
.body("{\n \"tokens\": [\n {\n \"chainId\": 123,\n \"tokenAddress\": \"<string>\",\n \"tokenSymbol\": \"<string>\"\n }\n ]\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://trails-api.sequence.app/rpc/Trails/GetTokenPrices")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"tokens\": [\n {\n \"chainId\": 123,\n \"tokenAddress\": \"<string>\",\n \"tokenSymbol\": \"<string>\"\n }\n ]\n}"

response = http.request(request)
puts response.read_body
{
  "tokenPrices": [
    {
      "token": {
        "chainId": 123,
        "tokenAddress": "<string>",
        "tokenSymbol": "<string>"
      },
      "updatedAt": "<string>",
      "priceUsd": 123
    }
  ]
}
{
"error": "WebrpcEndpoint",
"code": 0,
"msg": "endpoint error",
"status": 400,
"cause": "<string>"
}
{
"error": "WebrpcBadResponse",
"code": -5,
"msg": "bad response",
"status": 500,
"cause": "<string>"
}

Overview

The GetTokenPrices endpoint retrieves current USD prices for one or more tokens. This is useful for displaying real-time token values, calculating transaction costs, and showing users estimated amounts in fiat currency.

Use Cases

  • Display token values in USD in your UI
  • Calculate total transaction costs in fiat
  • Show users how much they’ll receive in USD
  • Build portfolio value displays
  • Create price alerts or notifications
  • Compare token values across chains

Request Parameters

Required Fields

  • tokens (Token[]): Array of token objects to get prices for

Token Object Structure

Each token object should include:
  • chainId (number): The chain ID where the token exists
  • tokenAddress (string): The token contract address
  • tokenSymbol (string, optional): Token symbol for reference

Response

The response includes:
  • tokenPrices (TokenPrice[]): Array of token price objects

TokenPrice Object Structure

Each price object contains:
  • token (Token): The token information
    • chainId (number): Chain ID
    • tokenAddress (string): Token contract address
    • tokenSymbol (string): Token symbol
  • priceUsd (number): Current price in USD
  • updatedAt (string): Timestamp of last price update

Examples

Single Token Price

const response = await fetch('https://trails-api.sequence.app/rpc/Trails/GetTokenPrices', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    tokens: [
      {
        chainId: 1,
        tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC on Ethereum
        tokenSymbol: 'USDC'
      }
    ]
  })
});

const { tokenPrices } = await response.json();

console.log('USDC Price:', tokenPrices[0].priceUsd);
console.log('Updated:', tokenPrices[0].updatedAt);

Multiple Token Prices

import type { TokenPrice } from "@0xtrails/api";

const response = await fetch('https://trails-api.sequence.app/rpc/Trails/GetTokenPrices', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        tokens: [
            {
                chainId: 1,
                tokenAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH on Ethereum
                tokenSymbol: 'WETH'
            },
            {
                chainId: 1,
                tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC on Ethereum
                tokenSymbol: 'USDC'
            },
            {
                chainId: 137,
                tokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC on Polygon
                tokenSymbol: 'USDC'
            }
        ]
    })
});

const { tokenPrices } = await response.json();

tokenPrices.forEach((price: TokenPrice) => {
    console.log(`${price.token.tokenSymbol} on Chain ${price.token.chainId}:`,
        `$${price.priceUsd}`);
});

Calculate Transaction Cost

import type { TokenPrice } from "@0xtrails/api";

const response = await fetch('https://trails-api.sequence.app/rpc/Trails/GetTokenPrices', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        tokens: [
            {
                chainId: 1,
                tokenAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH on Ethereum
                tokenSymbol: 'WETH'
            },
            {
                chainId: 1,
                tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC on Ethereum
                tokenSymbol: 'USDC'
            },
            {
                chainId: 137,
                tokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC on Polygon
                tokenSymbol: 'USDC'
            }
        ]
    })
});

const { tokenPrices } = await response.json();

tokenPrices.forEach((price: TokenPrice) => {
    console.log(`${price.token.tokenSymbol} on Chain ${price.token.chainId}:`,
        `$${price.priceUsd}`);
});

Common Token Addresses

Ethereum (chainId: 1)

  • WETH: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
  • USDC: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
  • USDT: 0xdAC17F958D2ee523a2206206994597C13D831ec7
  • DAI: 0x6B175474E89094C44Da98b954EedeAC495271d0F

Polygon (chainId: 137)

  • WMATIC: 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270
  • USDC: 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
  • USDT: 0xc2132D05D31c914a87C6611C10748AEb04B58e8F

Base (chainId: 8453)

  • WETH: 0x4200000000000000000000000000000000000006
  • USDC: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913

Arbitrum (chainId: 42161)

  • WETH: 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
  • USDC: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831

Notes

  • Not all tokens have price data available
  • The updatedAt timestamp indicates when the price was last refreshed
  • Prices are returned in USD

Next Steps

QuoteIntent

Use token prices to display quote values in USD

GetIntent

Calculate total transaction costs with token prices

Body

application/json
tokens
object[]
required

[]Token

Response

OK

tokenPrices
object[]
required

[]TokenPrice