convertCryptoToFiat

Get a price of a token (using tokenAddress + chainId) in fiat. Only USD is supported at the moment.

Example

Basic usage

For native token (non-ERC20), you should use NATIVE_TOKEN_ADDRESS as the value for tokenAddress

import { convertCryptoToFiat } from "thirdweb/pay";
// Get Ethereum price
const result = convertCryptoToFiat({
fromTokenAddress: NATIVE_TOKEN_ADDRESS,
to: "USD",
chain: ethereum,
fromAmount: 1,
});
// Result: 3404.11
function convertCryptoToFiat(
): Promise<{ result: number }>;

Parameters

Type

let options: {
chain: Chain;
client: ThirdwebClient;
fromAmount: number;
fromTokenAddress: Address;
to: "USD";
};

Returns

let returnType: Promise<{ result: number }>;

a number representing the price (in selected fiat) of "x" token, with "x" being the fromAmount .