Estimate gas from within smart contract

233 Views Asked by At

Let's assume that a smart contract A is deployed in Moonbeam and a smart contract B is deployed in Binance Smart Chain.

Contract A sends transactions to contract B and vice versa like a ping-pong game. As long as both contracts A and B can estimate Gas accurately they can keep playing ping-pong until they run out of funds

Question: Is there a way to safely estimate gas from within sc A before sending the tx to scB?

Note: I am aware of how to estimateGasFee from front end using Axelar JS SDK

1

There are 1 best solutions below

0
On BEST ANSWER

You can only use the estimateGasFee method provided by the Axelar JS SDK. However, there is no direct way to estimate gas fees within a smart contract itself.

Since the transaction is going through the Axelar network -> destination chain and your solidity code only has access to data about the source chain, we can only access data via the Axelarjs SDK, not natively in your solidity code.