0

I am working on the frontend where I use try / catch to find errors and give appropriate messages to users. My smart contract has a payable function and I was at the point of catching errors regarding gas usage.

uint[] public theArray;




function myFunction(uint bigNumber) payable public {
         if(msg.value == 0.01 ether){
         theArray.push(bigNumber);}
else {if (msg.value == .05 ether){
            for (int i; i<50;i++)
            theArray.push(bigNumber);

        }
else { 
    revert();
}
}}

Now when I try to catch the errors, the same error can have two different 'outputs' (err.message). The examples:

Using MetaMask on Rinkeby testing network

If I send 0.05 ETH with 21,000 gas or even 21,001 (minimum amount) the error I am getting is:

Returned error: Error: Error: [ethjs-rpc] rpc error with payload

However if I send 0.05 ETH with 25,000 gas (not enough gas so it still fails) the error I am getting is:

Transaction has been reverted by the EVM

Could anyone explain me why if I increase the gas amount the error changes?

Another thing I noticed is that if I send an invalid amount such as 0.04 I am also getting

Transaction has been reverted by the EVM

1

Base on my observation and understanding. Might not be the best explanation out there.

  1. If I send 0.05 ETH with 21,000 gas or even 21,001 (minimum amount) the error I am getting is:

    Returned error: Error: Error: [ethjs-rpc] rpc error with payload

-For this error it may have been because of metamask itself, maybe play with the gasPrice and/or gasLimit. You can refer here or here for better understanding.


  1. However if I send 0.05 ETH with 25,000 gas (not enough gas so it still fails) the error I am getting is:

Transaction has been reverted by the EVM

Could anyone explain me why if I increase the gas amount the error changes?

-For this error, I ran the code and find that possible reason is the transaction happens and being proceeded. The parameters satisfies this part of the code. However in the midst of the process the gas ran out while the for loop is running which eats up most of the gas you have provided. Maybe try to increase the gas limit and this will be mined without error.

if (msg.value == .05 ether){
        for (int i; i<50;i++)
        theArray.push(bigNumber);

    }

  1. Another thing I noticed is that if I send an invalid amount such as 0.04 I am also getting

Transaction has been reverted by the EVM

With the last scenario the parameter simply just did not satisfy any of the condition that is why it is going straight to the last else which revert() it.

  • Thanks a lot. I am looking now to understand more about the first error! Regarding the second error, I know that if I increase the gas it will work. Just saw that it gives a different error from when sending 21000 so I was curious why – Cristian Sep 26 '18 at 14:11
  • Same here. I'd also want some answer with the first error butbase on the links that I've provided it is highly likely because of metamask, I'm just not sure why exactly. – vhie Sep 27 '18 at 2:09
  • I sent them an email. I will come back with an update as soon as I receive an answer – Cristian Sep 27 '18 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.