#RPC returned error for "eth_estimateGas": -32000 execution reverted

1 messages · Page 1 of 1 (latest)

unreal socket
#

Hi,
I am using:

I have everything setup for my project, metamask login working fine, contract read methods working fine, but contract write methods throw error shown in the post title .... its actually the eth_estimateGas function called under the hood by the Contract.Send() method and it is not for some reason able to get the gas estimate ... tried another RPC node, same result.
It doesnt provide any additional info about what causes the revert. I have found some info that you could need approval for transactions, but not sure if it could be realted and how to approve it.

Found some info regarding EVM.CreateApproveTransaction() in the old SDK docs but seems its not available in the current version.

Any help is highly appreciated.

unkempt pine
#

gas estimation error usualy means the approval amount hasn't been set if you're transferring tokens, if not then the abi, function name or arguments are incorrect (datatypes also need to match the solidity contract parameters)

unreal socket
#

lets narrow it dow a bit ...

if the function name is incorrect the error is:
Function not found

if the arguments are incorrect format the error is for example:
Character 'u' at index '3' is not valid alphanumeric character.
or
Too many arguments: 2 > 1

So I would say theese are out of the game.

I have got to a state where i get this error:
RPC returned error for "eth_estimateGas": 3 execution reverted: BEP40: transfer amount exceeds allowance 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002842455034303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365000000000000000000000000000000000000000000000000

So I would say its related to the approval amount, can you please point me how to make the approval ?
As I mentioned before only mention about approval is from the docs of old SDK here:
https://docs.gaming.chainsafe.io/legacy/in-game-marketplace#create-approval-transaction

But the EVM.CreateApproveTransaction() seems to be missing in current SDK 🤔

Allows for interaction with the ChainSafe Gaming SDK marketplace endpoints.

unreal socket
#

Maybe Ill add a bit of context. I have presale contrat and am calling write method on it which spends users tokens, so the transaction is made within the contract, obviously I need to approve it, but I have no idea how as there is not much info about approval in the docs.

unkempt pine
#

because it's just a contract send with the method being approve 🙂

#

so if we look at the approve function that every erc20 token has it's this

function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }
#

you can see it takes an address and a value as parameters

#

to use that within the sdk you would be calling the function like this with the tokenABI and tokenContract variables being for your erc20 token & the spender being the contract spending the tokens.

#
// 20 tokens with 18 decimals
BigInteger amount = (BigInteger)(20*1e18);

// Approval function
public void Approve(string _spender, BigInteger _amount)
    {
        try
        {
            object[] args =
            {
                _spender,
                _amount
            };
            Debug.Log($"Approving spend amount");
            var data = await Evm.ContractSend(Web3Accessor.Web3, "approve", TokenAbi, TokenContract, args);
            var response = SampleOutputUtil.BuildOutputValue(data);
            Debug.Log($"Approval TX: {response}");
        }
        catch (Web3Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }
#

Happy coding! sneakzDab

unreal socket
#

Oh man ... I was already trying that but it was throwing "Web3Exception: incorrect txn response format" on me ... now I figured out I need build for that to work, silly me 🤦

Thank you for the hints and for your time Sir ! 🙏