GOAT Network
App Development

Estimating Transaction Fees

GOAT Network uses an EIP-1559-style fee model with BTC-denominated gas costs. Estimate fees by combining gas usage with live base fee and priority fee data.

Fee Components

ComponentMeaning
Gas limitEstimated execution cost for the transaction
Base feeDynamic network fee from the latest block
Priority feeOptional tip to encourage faster inclusion
Max fee per gasThe cap your wallet or script is willing to pay
Fee estimation flow
Estimate gas usage
      |
      v
Read live fee data
      |
      v
Set maxPriorityFeePerGas
      |
      v
Compute maxFeePerGas
      |
      v
Send transaction with final limits

Code Examples

ethers.js fee estimation
import { JsonRpcProvider, parseUnits } from 'ethers';

const provider = new JsonRpcProvider('https://rpc.testnet3.goat.network');

const feeData = await provider.getFeeData();
const gas = await provider.estimateGas({
  from: senderAddress,
  to: tokenAddress,
  data: transferCalldata,
});

const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? parseUnits('0.00013', 'gwei');
const maxFeePerGas = (feeData.maxFeePerGas ?? 0n) || ((feeData.gasPrice ?? 0n) + maxPriorityFeePerGas);
const totalFee = gas * maxFeePerGas;
web3.js fee estimation
const gas = await web3.eth.estimateGas({
  from: senderAddress,
  to: tokenAddress,
  data: transferCalldata,
});

const block = await web3.eth.getBlock('latest');
const priorityFee = BigInt(await web3.eth.getMaxPriorityFeePerGas());
const baseFee = BigInt(block.baseFeePerGas);
const maxFeePerGas = (baseFee * 2n) + priorityFee;
const totalFee = BigInt(gas) * maxFeePerGas;

Transfer Example

ethers.js token transfer estimate
const gas = await provider.estimateGas({
  from: senderAddress,
  to: tokenAddress,
  data: transferCalldata,
});

const feeData = await provider.getFeeData();
const tx = {
  from: senderAddress,
  to: tokenAddress,
  data: transferCalldata,
  gasLimit: gas,
  maxFeePerGas: feeData.maxFeePerGas,
  maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
};

Best Practices

  1. Re-estimate gas right before sending a write transaction.
  2. Prefer live fee data over hard-coded values.
  3. Show the result to users in BTC, not ETH.
  4. Re-run the estimate if calldata or recipient values change.

On this page