x402-chainlink
    Preparing search index...

    Function usdToToken

    • Convert USD amount to token amount using Chainlink price feed

      Parameters

      • client: {}

        Viem public client

      • network: EVMNetworkId

        Network identifier

      • usdAmount: number

        Amount in USD (e.g., 1.00 for $1)

      • tokenSymbol: string

        Token symbol (ETH, LINK, etc.)

      • tokenDecimals: number

        Token decimals (18 for ETH, 18 for LINK)

      Returns Promise<bigint>

      Amount in token's smallest unit (wei for ETH)

      // Convert $10 USD to ETH wei
      const ethWei = await usdToToken(client, 'eip155:8453', 10.0, 'ETH', 18);
      console.log(`$10 = ${formatEther(ethWei)} ETH`);