Replies: 1 comment 3 replies
-
Which network are you using? If this is a local hardhat network, then if you restart it then you lose the allowance and have to re-approve. If this is a live network, then how long are you waiting it's possible that when you are estimating gas, the block containing the thx is no yet received on the node which you are using. It can be better to just approve on the fly if it is needed, e.g. const allowance = await contract.allowance(ownerAddress, spenderAddress);
if(allowance.lt(amount)) {
const approveTx = await contract.connect(ownerSigner).approve(spender, amount); // this tx should go through owner account
await approveTx.wait(); // wait for tx to confirm
}
// transfer now since allowance exists now
const transferTx = await contract.transferFrom(from, to, amount); // this tx should go through spender account |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone.
I had called the approve function and changed the account,but i still get the error:insufficient allowance.I confirm the account had sufficient allowance.The strange thing is that sometimes it can be called normally, most of the time it will throw this error directly.
Error:
Environment:
hardhat@2.13.1
metask@10.28.3
Contract:
ethres code:
Beta Was this translation helpful? Give feedback.
All reactions