x402-chainlink
    Preparing search index...

    Function tokenToUsd

    • Convert token amount to USD using Chainlink price feed

      Parameters

      • client: {}

        Viem public client

      • network: EVMNetworkId

        Network identifier

      • tokenAmount: bigint

        Amount in token's smallest unit

      • tokenSymbol: string

        Token symbol (ETH, LINK, etc.)

      • tokenDecimals: number

        Token decimals

      Returns Promise<number>

      Amount in USD

      // Convert 1 ETH to USD
      const usd = await tokenToUsd(client, 'eip155:8453', parseEther('1'), 'ETH', 18);
      console.log(`1 ETH = $${usd}`);