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