ethers.js: Error: gas required exceeds allowance or always failing transaction
i am trying to make transfer from wallet B to wallet C and wallet A is the owner of ERC20 tokens
and i got error (node:2168) UnhandledPromiseRejectionWarning: Error: gas required exceeds allowance or always failing transaction
for approveAndCall
method.
`const approveCall = async() => {
var gasNewPrice = await provider.estimateGas(transactionNew);
console.log(gasNewPrice);
var approved = await
contract.approveAndCall(fromAddress,numberOfTokens,gasNewPrice);
return approved;
}
const transferTokens = async() => {
var transaction = await contract.transferFrom(fromAddress,targetAddress,numberOfTokens)
return transaction;
};
approveCall().then(function (resultApprove) {
console.log(resultApprove);
transferTokens().then(function (resultTransfer) {
console.log(resultTransfer);
});
}); `
what went wrong ?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (4 by maintainers)
Commits related to this issue
- Resolve gas limit error — committed to lukepark327/Energy-X-Security-Hackathon by ricegood 5 years ago
This seems to be an issue with certain contracts with certain backends, where the backend fails to correctly estimate the gas. It seems more common when a contract calls to another contract. Which provider are you using?
The only really way to prevent this is to manually set your gas limit (instead of letting estimateGas from being used):
And then dial in the correct gas estimate per call. This can also be set in the ABI (and if you use viper will be added to the ABI for you). To use it in the Human-Readable ABI, you can use:
Not ideal, and if you find a way to make estimateGas behave, let me know. But for now, it seems like these cases require a manually set gasLimit.
Hello having issues with trading bot gas fees on the ropenstine network
Error: Returned values aren’t valid, did it run Out of Gas? at ABICoder.decodeParameters (/home/kraytonian/trading_bot/trading-bot/node_modules/web3-eth-abi/src/index.js:226:15) at Contract._decodeMethodReturn (/home/kraytonian/trading_bot/trading-bot/node_modules/web3-eth-contract/src/index.js:465:22) at Method.outputFormatter (/home/kraytonian/trading_bot/trading-bot/node_modules/web3-eth-contract/src/index.js:818:46) at Method.formatOutput (/home/kraytonian/trading_bot/trading-bot/node_modules/web3-core-method/src/index.js:163:54) at sendTxCallback (/home/kraytonian/trading_bot/trading-bot/node_modules/web3-core-method/src/index.js:473:33) at /home/kraytonian/trading_bot/trading-bot/node_modules/web3-core-requestmanager/src/index.js:147:9 at /home/kraytonian/trading_bot/trading-bot/node_modules/web3-provider-engine/index.js:159:9 at /home/kraytonian/trading_bot/trading-bot/node_modules/async/internal/once.js:12:16 at replenish (/home/kraytonian/trading_bot/trading-bot/node_modules/async/internal/eachOfLimit.js:61:25) at /home/kraytonian/trading_bot/trading-bot/node_modules/async/internal/eachOfLimit.js:71:9 at eachLimit (/home/kraytonian/trading_bot/trading-bot/node_modules/async/eachLimit.js:43:36) at /home/kraytonian/trading_bot/trading-bot/node_modules/async/internal/doLimit.js:9:16 at end (/home/kraytonian/trading_bot/trading-bot/node_modules/web3-provider-engine/index.js:134:5) at /home/kraytonian/trading_bot/trading-bot/node_modules/web3-provider-engine/subproviders/provider.js:19:5 at XMLHttpRequest.request.onreadystatechange (/home/kraytonian/trading_bot/trading-bot/node_modules/web3-providers-http/src/index.js:96:13) at XMLHttpRequestEventTarget.dispatchEvent (/home/kraytonian/trading_bot/trading-bot/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
@SirPhemmiey no, I did not use approve function my issue was, I was trying to transfer the more tokens than the contract had (my decimal was different when I was calling the contract and when I deployed the contract so could not figured out earlier).