Axelar query API
This module is a nice-to-have of common queries made into the Axelar network and its services that are abstracted into easy-to-use JavaScript one-liners.
Install the AxelarJS SDK module (AxelarQueryAPI
)
Install the AxelarJS SDK:
npm i @axelar-network/axelarjs-sdk
Instantiate the AxelarQueryAPI
module:
const sdk = new AxelarQueryAPI({
environment: "testnet",
});
Possible queries
estimateGasFee
This is a useful query for GMP transactions, when invoking callContract
or callContractWithToken
to get an estimate of the appropriate gas payment to be made to the gas receiver on the source chain.
IMPORTANT NOTES:
- You must ensure the correct
gasLimit
is used for your gas estimation. The (optional)gasLimit
parameter can be used here to override the default 700K gas limit that is used. - The
minGasPrice
andgasMultipler
parameters can be adjusted to enhance execution certainty of cross-chain transactions. - The response to the method gives a single value (in
wei
) of the total estimated gas required for the cross-chain call. In the GMPParams parameter, there is an option to show a full breakdown of fees instead by specifyingtrue
forshowDetailedFees
. If you do this, you will have to add the individual components of the fees yourself, e.g.(baseFee + executionFeeWithMultiplier)
for regular way GMP calls, or(baseFee + executionFeeWithMultiplier + expressFee)
for GMP Express calls
interface GMPParams {
showDetailedFees: boolean;
transferAmount: number; // In terms of symbol, not unit denom, e.g. use 1 for 1 axlUSDC, not 1000000
destinationContractAddress: string;
sourceContractAddress: string;
tokenSymbol: string;
}
export interface AxelarQueryAPIFeeResponse {
expressFee: string;
baseFee: string;
executionFee: string;
executionFeeWithMultiplier: string;
gasMultiplier: number;
gasLimit: number;
srcGasPrice: string;
minGasPrice: string;
apiResponse: any;
isExpressSupported: boolean;
}
/**
* Calculate estimated gas amount to pay for the gas receiver contract.
* @param sourceChainId
* @param destinationChainId
* @param sourceChainTokenSymbol
* @param gasLimit (Optional) An estimated gas amount required to execute `executeWithToken` function. The default value is 700000 which should be sufficient for most transactions.
* @param gasMultiplier (Optional) A multiplier used to create a buffer above the calculated gas fee, to account for potential slippage throughout tx execution, e.g. 1.1 = 10% buffer. supports up to 3 decimal places
* @param minGasPrice (Optional) A minimum value, in wei, for the gas price on the destination chain that is used to override the estimated gas price if it falls below this specified value.
* @param gmpParams (Optional) Additional parameters for GMP transactions, including the ability to see a detailed view of the fee response
* @returns
*/
public async estimateGasFee(
sourceChainId: EvmChain | string,
destinationChainId: EvmChain | string,
sourceChainTokenSymbol: GasToken | string,
gasLimit: number = DEFAULT_ESTIMATED_GAS,
gasMultiplier = 1.1,
minGasPrice = "0",
gmpParams?: GMPParams
): Promise<string | AxelarQueryAPIFeeResponse>
getTransferFee
Given a source chain, destination chain and amount of an asset, this query retrieves the base fee that the network would assess for that transaction.
/**
* Gets the transfer fee for a given transaction
* @param sourceChainName
* @param destinationChainName
* @param assetDenom
* @param amountInDenom
* @returns
*/
public async getTransferFee(
sourceChainName: string,
destinationChainName: string,
assetDenom: string,
amountInDenom: number
): Promise<TransferFeeResponse>