LogoLogo
  • ⏩Introduction
    • Hyperlane Introduction
    • Getting started
    • Why Should You Use Hyperlane?
  • Permissionless Interoperability
    • Overview
    • Deploy Hyperlane
    • Warp Routes
      • Deploy a Warp Route
      • Deploy a UI for your Warp Route
    • Modular Rollup Interoperability
  • Build With Hyperlane
    • Quickstarts
      • Messaging
      • Accounts
      • Queries
      • hyperlane-quickstart repo
    • Guides
      • Finding my messages
      • Automatically pay for interchain gas
      • Manually pay for interchain gas
      • Choosing an interchain gas paymaster contract
      • Unit testing
      • Specifying an ISM
      • V2 migration guide
    • Explorer
      • Debugging messages
      • Configuring PI Chains
      • REST API
      • GraphQL API
    • Troubleshooting/Developer FAQ
    • Example apps
  • APIs and SDKs
    • Messaging API
      • Send
      • Receive
    • Accounts API
    • Queries API
    • Warp Route API
    • Interchain gas paymaster API
    • Hyperlane App Framework
      • Example usage
        • HelloWorld
        • Interchain Token
      • Solidity SDK
        • HyperlaneConnectionClient
        • Router
      • NodeJS SDK
        • RPC Providers
        • Deployment
        • Interchain testing
        • Quoting gas payments
        • App Abstraction
    • Hooks API
      • Contract addresses
  • Protocol
    • Overview
    • Mailbox
    • Interchain security modules
      • Interface
      • Multisig ISM
      • Routing ISM
      • Aggregation ISM
      • Optimistic ISM
      • Wormhole ISM
      • Hook ISM
      • CCIP-Read ISM
    • Interchain gas payments
    • Staking and slashing
    • Agents
      • Validators
      • Relayers
      • Watchtowers
    • Warp Routes
    • Implementation Guide
  • Operators
    • Validators
      • Guide
      • AWS setup
      • Monitoring and alerting
    • Relayers
      • Guide
      • Message filtering
    • Agent keys
      • Hexadecimal keys
      • AWS KMS keys
    • Agent configuration
      • Configuration reference
    • Running with docker compose
  • Resources
    • FAQ
    • Glossary
    • Contract addresses
      • Permissionless Deployment Contract Addresses
    • Domain identifiers
      • Permissionless Domain Identifiers
    • Default ISM settings
    • Coming Soon: Hyperlane v3
    • Token sources & faucets
    • Latencies
    • Github
    • Discord
    • Website
Powered by GitBook
On this page
  1. APIs and SDKs
  2. Hyperlane App Framework
  3. NodeJS SDK

Quoting gas payments

Pay for message delivery on the origin chain

Applications can use the HyperlaneIgp in the Hyperlane SDK to quote when dispatching a message. See the example below illustrating how to estimate and pay interchain gas payments.

Getting a quote Using the SDK

An interchain gas payment quote will call the quoteGasPayment function on an Interchain Gas Paymaster contract.

In this example, we'll get an interchain gas payment quote for a message from Avalanche to Polygon.

First, let's create the HyperlaneIgp instance. See RPC Providers for creating a MultiProvider with your own RPC providers.

import {
  chainConnectionConfigs,
  InterchainGasCalculator,
  MultiProvider
} from "@hyperlane-xyz/sdk";
import { ethers } from "ethers";

// Set up a MultiProvider with the default providers.
const multiProvider = new MultiProvider({
  avalanche: chainConnectionConfigs.avalanche,
  polygon: chainConnectionConfigs.polygon,
});

// Create the HyperlaneIgp instance.
const igp = HyperlaneIgp.fromEnvironment(
  'mainnet',
  multiProvider,
);

There are two functions that can be used to quote interchain gas payment. See Choosing an interchain gas paymaster contract to understand which IGP contract you should be using and to get more information on gas amounts.

Function
IGP contract
Gas amount

quoteGasPaymentForDefaultIsmIgp

The provided DefaultIsmInterchainGasPayaster for use with the default ISM

The gas amount used by the message's recipient handle function

quoteGasPayment

The provided InterchainGasPaymaster

All gas required to process the message, which includes the cost of ISM verification

Now, we can use the HyperlaneIgp to find how much AVAX should be paid for our message from Avalanche to Polygon that we expect to consume 200,000 gas in the recipient contract's handle function.

// Calculate the AVAX payment to send from Avalanche to Polygon,
// with the recipient's `handle` function consuming 200,000 gas.
const avaxPayment = await igp.quoteGasPaymentForDefaultIsmIgp(
  'avalanche',
  'polygon',
  ethers.BigNumber.from(200_000),
);

console.log('Avalanche -> Polygon payment for 200k handle gas on destination:');
console.log(`${ethers.utils.formatEther(avaxPayment)} AVAX`);

// At the time of writing, this outputs:

// Avalanche -> Polygon payment for 200k handle gas on destination:
// 0.00071510955746088 AVAX
PreviousInterchain testingNextApp Abstraction

Last updated 2 years ago