Embedded Wallets
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.
  • walletToken: string - The wallet token of the wallet to estimate gas for.
  • refreshToken: string - The refresh token for authentication. Use this if you want to allow SDK automatically refresh the wallet token.

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.
  • walletToken?: string - The new wallet token of the wallet.
  • refreshToken?: string - The new refresh token of the wallet.

Example Usage

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

Response Example

{
  "gasLimit": "21000",
  "gasPrice": "6776647976",
  "maxFeePerGas": "14457061074",
  "maxPriorityFeePerGas": "1000000000",
  "walletToken": "your-new-wallet-token",
  "refreshToken": "your-new-refresh-token"
}
ℹ️

The SDK will automatically refresh the wallet token and return the new wallet token and refresh token if the refresh token is provided.

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).