Fetch, calculate, and display transaction fees as USD amounts in your wallet UI.
Arc uses USDC as its native gas token, so fees are inherently denominated in
USD. The eth_gasPrice and eth_feeHistory RPCs return values in USDC wei (18
decimals). The EWMA fee smoothing model keeps fees predictable—dramatic spikes
are unlikely. Display fees as $X.XX (or ~$0.01), never as “Gwei” or “ETH.”
Prerequisites
Before you begin:
You have an RPC endpoint for Arc.
You are using an EIP-1559-compatible library (viem, ethers.js, or equivalent).
You understand that Arc’s native currency is USDC.
Steps
Step 1. Fetch the current gas price
Use eth_gasPrice for a single value or eth_feeHistory for historical base
fees and priority fee percentiles.
import { createPublicClient, http, formatUnits } from "viem";import { arc } from "viem/chains";const client = createPublicClient({ chain: arc, transport: http("https://rpc.arc.circle.com"),});// Simple: current gas price in USDC weiconst gasPrice = await client.getGasPrice();console.log("Gas price (wei):", gasPrice);// Detailed: recent base fee historyconst feeHistory = await client.getFeeHistory({ blockCount: 4, rewardPercentiles: [25, 50, 75],});console.log("Latest base fee (wei):", feeHistory.baseFeePerGas.at(-1));
Step 2. Estimate gas for the transaction
Use eth_estimateGas to determine how much gas your transaction requires.
// Native USDC transfer: ~21,000 gasconst simpleTransferGas = 21_000n;// ERC-20 token transfer or contract call: use estimateGasconst contractGas = await client.estimateGas({ account: "0xYourAddress", to: "0xContractAddress", data: encodedCalldata,});
Typical gas costs:
Transaction type
Approximate gas
Native USDC send
21,000
ERC-20 transfer
~65,000
Contract interaction
Varies—always estimate
Step 3. Build EIP-1559 fee parameters
Arc supports EIP-1559 transactions. Set maxFeePerGas and
maxPriorityFeePerGas:
const latestBlock = await client.getBlock();const baseFee = latestBlock.baseFeePerGas!;// 2x base fee is generous—Arc's EWMA smoothing keeps fees stableconst maxFeePerGas = baseFee * 2n;// Priority fee of 0 is acceptable on Arc (validators don't require tips)const maxPriorityFeePerGas = 0n;
Set maxFeePerGas to at least 20 Gwei. Arc enforces a hard floor:
transactions with maxFeePerGas lower than 20 Gwei are rejected with no error
receipt. The EWMA smoothing model keeps fees gradual and predictable.
Step 4. Calculate the maximum fee in USD
Multiply the gas limit by maxFeePerGas, then convert from 18-decimal USDC wei
to a dollar amount.
function calculateMaxFeeUsd(gasLimit: bigint, maxFeePerGas: bigint): string { const maxCostWei = gasLimit * maxFeePerGas; // USDC has 18 decimals as the native gas token on Arc // Since 1 USDC = $1, the numeric value IS the USD cost const usdCost = formatUnits(maxCostWei, 18); return usdCost;}// Example: simple transferconst maxFee = calculateMaxFeeUsd(21_000n, maxFeePerGas);console.log(`Max fee: $${Number(maxFee).toFixed(6)}`);
Step 5. Format fees for display
Show fees as a dollar amount. Use ~ to indicate the value is an estimate.
Standard libraries like ethers.js and viem label the native currency as “ETH”
by default. You must override this in your UI. Displaying “0.00042 ETH”
instead of ”~$0.01” confuses users and misrepresents the cost.
Users are only charged gasUsed * effectiveGasPrice. The difference between
maxFeePerGas and the actual effective gas price is refunded. It’s safe to
show the maximum estimate in your UI with language like “Max fee” or “Up to.”