GET fees

Calculating required gas to execute given calldata can be confusing in a multi-chain context. This endpoint knows the best way to calculate L1 + L2 fees for all chains.

For L1s and sidechains, the RPC method get_gasEstimate is sufficient. But L2s like Optimism and Base have both a L2 and L1 component to calculate separately. Arbitrum does too, but returns the sum over get_gasEstimate.

Instead of worrying about those details, use our HTTP endpoint.

Endpoint

/fees

Request

Parameters

  • chainId (number): EVM chainId that tx will be sent on.

  • calldata (string): Calldata of tx to get fees for. Construct on client-side with ethers or similar tool.

  • contractAddress (string: 0x...): Contract address to send calldata to.

  • fromAddress (string: 0x...): Address of wallet that will sign the transaction.

Response

  • amountUsd (string): Total USD cost of sending the tx.

  • amountNative (string): Total native ETH cost of sending the tx.

  • parts (IPart[]): Array of all the components of the fee.

IPart

  • name (string):

    • gas-native: When gas corresponds to a L1 or L2 and the only gas component is native. Eg. ETH and MATIC.

    • gas-l1: When gas corresponds to a L2 and there is a L1 component. Eg. OP and Base.

    • gas-l2: When gas corresponds to a L2 and there is a L2 component. Eg. OP and Base.

    • gas-all: When gas corresponds to a L2 and L1 and L2 components are reported together. Eg. Arbitrum.

  • amountUsd (string): Total USD cost of sending the tx.

  • amountNative (string): Total native ETH cost of sending the tx.

  • amountCurrency (ICurrency): Currency corresponding to amountNative. Eg. ETH and MATIC.

Example

Get the cost to send USDC on Base.

Request

curl -X POST https://engine.omo.so/api/v1/fees \
-H "Content-Type: application/json" \
-d '{
    "contractAddress": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "chainId": 8453,
    "calldata": "0xa9059cbb0000000000000000000000002680d6e9b4b54fbf1b8e912909531a1306e0e6a900000000000000000000000000000000000000000000000000000000000f4240",
    "fromAddress": "0x2680d6e9b4b54fbf1b8e912909531a1306e0e6a9"
}'

Response

{
  "amountUsd": "0.166303",
  "amountNative": "0.000070872272560256",
  "parts": [
    {
      "name": "gas-l2",
      "amountUsd": "0.000123",
      "amountNative": "0.000000052601432536",
      "amountCurrency": {
        "address": "0x0000000000000000000000000000000000000000",
        "chain": {
          "name": "Base",
          "chainId": 8453
        },
        "decimals": 18,
        "name": "ETH"
      }
    },
    {
      "name": "gas-l1",
      "amountUsd": "0.166180",
      "amountNative": "0.000070819671127720",
      "amountCurrency": {
        "address": "0x0000000000000000000000000000000000000000",
        "chain": {
          "name": "Base",
          "chainId": 8453
        },
        "decimals": 18,
        "name": "ETH"
      }
    }
  ]
}

Last updated