Embedded Wallets
How to
Wallet Operation
Estimate Gas

Estimate Gas

API Documentation: Estimate Gas

Overview

This API endpoint allows users to estimate gas for transaction using their MPC wallet.

  • HTTP Method: POST
  • Endpoint: /api/<VERSION>/wallet/estimate-gas

Request Body Parameters

  • network (required if chainId empty): The network used for transactions. You can see Networks Reference to get the network code.
  • chainId (required if network empty): The chain ID of the network used for transactions.
  • type (required): Type of transaction user want to estimate the gas. Available options are send-coin, send-token, transfer-erc721, transfer-erc1155, custom.
  • to (optional): Recipient wallet address.
  • amount (optional): Amount to send in decimal units (e.g., 0.123) (e.g., [2, 4] for batch transfer of ERC-1155 tokens)
  • tokenId (optional): Token id of the ERC-721 or ERC-1155 token user want to send (input array of tokenId for batch transfer, input single tokenId for single transfer).
  • tokenAddress (optional): Address of the token user want to send.
  • transaction (optional): Raw transaction data user want to estimate the gas.

Example Request Body

{
    "network": "ethereum",
    "chainId": "1",
    "type": "send-coin",
    "to": "0xBfE64B4b628E0998A03e2522B051Cf1B4661c964",
    "amount": "0.015",
}

Request

Request Headers

  • Authorization (required): JWT token which was generated when user login and do not have an MPC wallet.
  • x-client-secret (required): Client secret which was generated when register in Xellar Embedded Wallet API Service Dashboard.

Example Request Syntax

curl -X POST -H "Content-Type: application/json" -H "x-client-secret: $YOUR_CLIENT_SECRET" -H "Authorization: Bearer $YOUR_ACCESS_TOKEN" -d '{
    "network": "ethereum",
    "chainId": "1",
    "type": "custom",
    "transaction": {
        "from":"0x5B3A69CD0984c8621c75c54aa4dCA89e382523A9",
        "to":"0x5B3A69CD0984c8621c75c54aa4dCA89e382523A9",
        "data":"0x",
        "nonce":"0x00",
        "gasPrice":"0x1cb3fa334b",
        "gasLimit":"0x5208",
        "value":"0x00"
    }
}' <BASE_URL>/api/<VERSION>/wallet/estimate-gas

Response

The response will include a JSON object with the following properties:

  • status (number): The HTTP status code of the response (e.g., 200 for success).
  • message (string): A message providing additional information about the operation.
  • data (object): An object containing the gas data from estimate gas.

Example Response

{
    "status": 200,
    "message": "Estimate Gas is successful",
    "data": {
        "estimateGas": {
            "gasLimit": "21000",
            "gasPrice": "6776647976",
            "maxFeePerGas": "14457061074",
            "maxPriorityFeePerGas": "1000000000"
        }
    }
}