Contract call always fails for my contract on sokol

This is my contract address: 0xa6dc5e5b21d32929b4545126ec95670032c0c178

code snippet:

contract.purchaseTokens(ethers.utils.parseEther(amount),{gasLimit:41720,gasPrice:ethers.utils.parseUnits('1', 'gwei')});

To make a successful purchaseTokens call , I tried to increase gasLimit and gasPrice but fails.

Initially i got

Error: Out of gas

and then i increase the gasPrice , i got

Error: (Awaiting internal transactions for reason)

I call again without changing gasPrice , i got

Error: Reverted

Here is the complete transaction list:

Need Help

do you mind to verify the code of your contract?


Thanks for your reply.

Sorry, I can’t share the code. i have contract address, ABI file and wallet mnemonics only. The contract is developed by another developer.

I did testing in Ropsten it works fine without any issue

The main issue is due to gas estimation. In my previous post, you have said to set gas price to 1 Gwei. Even if i set gas price to 1 Gwei it fails .

Since eth_estimateGas method is not working in POA sokol . Is there any alternate way i can estimate gasLimit.

So my question is How can i estimate gasLimit ?

Hi, could you share ABI for diagnostics?

1 Like

In addition, could you specify, where did you get the gas limit 41720 from? Did you try to estimate gas of the contract method by means of web3 in Sokol?

1 Like

The gas limit 41720 is set by me as i did not get response from eth_estimateGas.

You can check my post related to this:Getting error "The execution failed due to an exception." in sokol RPC call - eth_estimateGas.

var block = web3.eth.getBlock("latest");
console.log("gasLimit: " + block.gasLimit);

If i get gasLimit in this way will it work ?

Because in past i used just like this to make contract call in ropsten, few calls fails


And also, what is the address of this contract in Ropsten? the same as for Sokol?

Setting values like this works . I was able to call non constant functions without any issue

     gasPrice : ethers.utils.parseUnits('1', 'gwei'),
     gasLimit :  await poaProvider.getBlock('latest').gasLimit,

Sure, it will work in all cases, when required gas for method execution is less than block gas limit. Meanwhile, it doesn’t mean, that all gas from gasLimit consumed.

If for some reasons gas is not estimated, and you know how much method consumes from other networks (like Ropsten in your case), the other option to get gas limit is to hardcode this value and calculate gas limit as this value + delta, where delta is a small addition, let’s say 10% of value. Of course, it will work if method’s logic doesn’t highly depend on input values (I mean, for example, loop in the method can significantly change gas consuming depending on the number of iterable steps)

1 Like