Hey, Iām using permit for approval via signatures for ERC20 Tokens, I need to execute the permit function from the back-end, I created a transaction but got āInvalid signatureā. Permit is called from ERC20 contract ABI.
Hereās my code:
async function makePermit() {
const contract = new web3.eth.Contract(erc20ABI, contractAddress);
const privateKey = "";
const privateAccount = web3.eth.accounts.privateKeyToAccount(privateKey);
const permit = await contract.methods.permit(account, receiverAddress, 1000, 1988064000, 27, r, s);
const tx = {
from: privateAccount.address,
to: account,
data: permit.encodeABI(),
gas: await permit.estimateGas({ from: privateAccount.address }),
gasPrice: await web3.eth.getGasPrice()
};
const signedTx = await web3.eth.accounts.signTransaction(tx, privateKey);
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);
console.log(receipt);
}
To split my signature I use this:
const pureSig = sig.replace("0x", "")
r = new Buffer.from(pureSig.substring(0, 64), 'hex')
s = new Buffer.from(pureSig.substring(64, 128), 'hex')
v = new Buffer.from((parseInt(pureSig.substring(128, 130), 16)).toString());
Error screenshot:
Any thoughts? Thanks.