Contract call always fails for my contract on sokol


#1

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:
https://blockscout.com/poa/sokol/address/0xa6dc5e5b21d32929b4545126ec95670032c0c178/transactions

Need Help


#2

Hi,
do you mind to verify the code of your contract?


#3

Hi,

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 ?


#4

Hi, could you share ABI for diagnostics?


#5

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?


#6

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


#7

@Ajit_Soman

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


#10

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,
   }

#11

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)