Background

@skip-go/core — the Typescript Package we build to abstract away the complexity of calling Skip Go API directly — provides additional functionality for building transactions. Since we’ve heard setting gas amount, fee amount, and gas price well is really tricky, we try hard to use reasonable, reliable defaults for these values. But we also expose a lot of functionality that lets folks override these defaults and customize fees (e.g. use non-default tokens for fees) and gas.

This doc describes all the tooling we’ve built into the library to get information about gas & fees, and customize how they’re set on your transactions.

Video Overview

Here’s a video overview for folks who are more visual: https://www.loom.com/share/063e96e126d2422bb621b5b0ecf9be2c

SkipRouter functions for getting info about gas and fees

These functions are useful for getting information about our default gas and fee values or for estimating the fee for a particular transaction (e.g. so you can build a working MAX button)

SkipRouter.getRecommendedGasPrice

This returns the gas price (i.e. the price of a single unit of gas) the API recommends you use for transactions on a particular chain.

JavaScript
async getRecommendedGasPrice(chainID: string) -> GasPrice

GasPrice is a cosmjs type giving the recommended fee denom and recommend price amount (fee/gas):

JavaScript
type GasPrice = {
  denom: string;
  amount: Decimal
}

SkipRouter.getFeeInfoForChain

This will return high, medium, and low gas prices for a particular chain, given by chainID, along with the default fee denom as a FeeAsset object:

JavaScript
type FeeAsset = {
  denom: string;
  gasPrice: GasPriceInfo;
};

type GasPriceInfo = {
  low: string;
  average: string;
  high: string;
};

An undefined response indicates that the API cannot find up-to-date gas price information for the chain.

SkipRouter.getFeeForMessage

This will give you the estimated fee and gas for a particular multichainMsg returned by the API.

JavaScript
async getFeeForMessage(
    msg: MultiChainMsg,
    gasAmountMultiplier: number = DEFAULT_GAS_MULTIPLIER,
    signer?: OfflineSigner,
    gasPrice?: GasPrice,
  ) 

If you provide no additional arguments other than your signer and message, it will use the default gas price and gas amount multipliers in the skip-router, but you can override anything to customize your estimation for your use case:

  • You can override the gas price in the gasPrice argument (By default, we’re pulling this data from various chain registries and serving it through the API)
  • You can override the gas amount multiplier, which provides a multiplicative buffer for the amount of gas the chain estimates a transaction will consume, in the gasAmountMultiplier argument. (By default, this is 1.5)

The return type of the function is a cosmjs.StdFee, which includes the following fields:

  • amount: The estimated fee amount and denom for the fee
  • gas: The gas amount for the transaction

Settings on ExecuteRouteOptions for customizing how gas & fees are set on transactions

ExecuteRouteOptions.getGasPrice

This field in ExecuteRouteOptions allows you to override our default gas price on a per chain basis for any transactions created in the router (e.g. in executeRoute):

getGasPrice?: (chainID: string) => Promise<GasPrice | undefined>;

The argument is a function that takes in a chain id and returns a gas price for that chain as a GasPrice object from CosmJS

JavaScript
type GasPrice = {
  denom: string;
  amount: Decimal
}

If you provide a function that only returns a price for a subset of chains, the router will use its default price in cases where yours is missing. If it can’t find a default price for a chain, it will error.

ExecuteRouteOptions.gasAmountMultiplier

This field in ExecuteRouteOptions allows you to override the default gas multiplier used in the SDK by default. (The default value is 1.5). Increases this value gives you higher confidence that your transaction will not run out of gas while executing, but increases the fee for the end user.

The gas multiplier increases a transaction’s gasAmount multiplicatively. To get a final gas amount, the router:

  • Simulates a transaction to get an initial gasAmount
  • Multiplies the gas consumed in the simulation by gasAmountMultiplier