Hey, I’m using the permit function to give approval to an specified amount of tokens with signature. I get the split r
, s
and v
values from the signature, and I then execute my permit function from back-end with a transaction and a private key. Here’s the problem, when sending the signed transaction to the net, it will suddenly throw out an error: Transaction reverted by EVM
. When I go to the transaction hash on etherscan, it says that it got out of gas. Strange thing here, is that I double the estimated gas fees, so it shouldn’t run out of gas. Sometimes the transaction itself doesn’t even use all the gas but just throws out that error.
PS: I tried on remix with ropsten net and it didn’t throw out that error.
Here’s an example:
The gas that I have given is 58200, but it only uses 23280 (see screenshot).
The transaction hash:
https://etherscan.io/tx/0x7f0b702bd886f13ff50f4afb7c8b98626227b4be884fdfa4870449cfb28f3012.
Code for executing the permit:
async function makePermit() {
try {
const contract = new web3.eth.Contract(erc20ABI, contractAddress);
const permit = await contract.methods.permit(account, receiverAddress, 1000, 1988064000, v, r, s);
let gasAmount = 23280; //Default value
const estimatedGasOption = web3.eth.estimateGas({
from: receiverAddress,
to: account,
data: permit.encodeABI(),
}).then(function(ga) {
gasAmount = ga * 2.5;
console.log(gasAmount);
});
const tx = {
from: receiverAddress,
to: contractAddress,
data: permit.encodeABI(),
gas: gasAmount,
gasPrice: await web3.eth.getGasPrice()
};
const signedTx = await web3.eth.accounts.signTransaction(tx, privateKey);
console.log(signedTx);
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction); // error is thrown here
console.log(receipt);
} catch (error) {
console.log(error);
}
}
Could this be something that influence the error?
- Wrong r,s and v values
- Something is wrong when creating the permit message to sign it.
About permit: https://eips.ethereum.org/EIPS/eip-2612
Thanks for your support!