SDK
Javascript
How to
Wallet Operation
Estimate Gas

Estimate Gas

This method allows you to estimate gas for transactions using your MPC wallet.

Method Signature

async estimateGas(config: EstimateGasConfig): Promise<EstimateGasResponse>

Parameters

  • config: EstimateGasConfig - The configuration for estimating gas.

EstimateGasConfig

  • network: Network (required) - The network used for transactions.
  • type: 'send-coin' | 'send-token' | 'transfer-erc721' | 'transfer-erc1155' | 'custom' (required) - Type of transaction to estimate gas for.
  • to: string (required for send-coin, send-token, transfer-erc721, transfer-erc1155) - Recipient wallet address.
  • amount: string (required for send-coin, send-token) - Amount to send in decimal units (e.g., "0.123").
  • tokenId: string | string[] (required for transfer-erc721, transfer-erc1155) - Token ID(s) of the ERC-721 or ERC-1155 token(s) to send.
  • tokenAddress: string (required for send-token, transfer-erc721, transfer-erc1155) - Address of the token contract.
  • tokenAmount: string | string[] (required for transfer-erc1155) - Amount of tokens to transfer. Use an array for batch transfer.
  • transaction: object (required for custom) - Raw transaction data for custom transactions.

Returns

Promise<EstimateGasResponse> - An object containing the following properties:

  • gasLimit: string - The estimated gas limit.
  • gasPrice: string - The estimated gas price.
  • maxFeePerGas: string - The maximum fee per gas.
  • maxPriorityFeePerGas: string - The maximum priority fee per gas.

Example Usage

const estimateGasCoin = await sdk.wallet.estimateGas({
  type: 'send-coin',
  network: Network.ETHEREUM,
  to: '0xBfE64B4b628E0998A03e2522B051Cf1B4661c964',
  amount: '0.015'
});
console.log(estimateGasCoin);

Response Example

{
  "gasLimit": "21000",
  "gasPrice": "6776647976",
  "maxFeePerGas": "14457061074",
  "maxPriorityFeePerGas": "1000000000"
}
ℹ️

The response is an object containing the estimated gas parameters for the specified transaction type and network.

Additional Information

  • This method requires a valid wallet token in the SDK configuration.
  • The gas estimates are returned as strings to preserve precision for large numbers.
  • Different transaction types require different parameters in the EstimateGasConfig object.
  • For ERC-1155 batch transfers, use arrays for tokenId and tokenAmount.

For more information, see the Xellar Estimate Gas API Documentation (opens in a new tab).