So whenever I'm calling any function from my frontend on testnet my gasPrice is 1 GWEI by default

And on testnet(working fine on Buidler local EVM) most of my functions are giving below errors:
inpage.js:1 MetaMask - RPC Error: gas required exceeds allowance (10000000) or always failing transaction {code: -32000, message: "gas required exceeds allowance (10000000) or always failing transaction"}
contribution-modal-widgets.js:99 Contribution Error Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"code":-32000,"message":"gas required exceeds allowance (10000000) or always failing transaction"}, method="estimateGas", transaction={"from":"0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150r4","to":"0x2e1739C5D061082e85E1d6D17f91e2d56bDF3Bf2","data":"0x0d87ec9b0000000000000000000000000000000000000000000000000000000000989680"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.0.9)
at Logger.makeError (ethers.umd.js:3659)
at Logger.throwError (ethers.umd.js:3668)
at checkError (ethers.umd.js:24041)
at Web3Provider.<anonymous> (ethers.umd.js:24415)
at step (ethers.umd.js:23992)
at Object.throw (ethers.umd.js:23973)
at rejected (ethers.umd.js:23965)
Tried a lot of things to make it work, even provided hardcoded gas but that did not work.
I'm testing my dapp on testnet right now and I'm on the verge of deploying on mainnet but because of this issue I'm not able to deploy it on mainnet.
gas required exceeds allowance (10000000) or always failing transaction
If you are passing a lot of gas and still if you get this, it probably means that always failing transaction is the case. You can look for any require statemenets in your contract that might be causing the fail?
Actually its happening randomly for same functions. . In case of revert transactions I've revert messages but I don't get the revert message and instead of that I get this?
Its my first dapp I'm trying to deployed. Facing these issues on testnet itself. Was not facing on localhost and that's understandable because of the env conditions.
At many a places where I expect that function might need more gas I'm first calling contract.estimateGas.function() and then in the actual invocation I've multiplying it up to 5 times too depending on the function like if I've a for loop and transfers in that case I'm doing
estimateGas = await contract.estimateGas.forLoopTransferFunction()
await contract.forLoopTransferFunction({gasLimit: estimateGas.mul(5})
So I think gas shouldn't be an issue... Sorry if I'm mixing multiple things in here.
Its just if some revert is getting hit then should be getting the revert msg like in localhost instead of this long unexpected message.
Getting revert reasons are actually tricky to get because of various backends following different rules. Though ethers.js show it if it was received in the response from node.
You can see https://github.com/ethers-io/ethers.js/issues/368, https://github.com/ethers-io/ethers.js/issues/446.
As a quick example, I gave a shot to display revert reasons in our dapp UI, but it has fixed backend software i.e. parity so we could use their trace API) by overriding ethers js methods to create a custom json rpc provider. This might not work for when you have different backends, since each backend has different set of non-standard APIs. Though infura uses parity, and I asked them if they could expose their trace APIs, which would make this code work with infura.
I wish all backends could adhere to a standard wrt to errors since errors are helpful to save a lot of time debugging. This is something I'd like to suggest if we can do some magic in ethers js under the hood to fetch the revert reason (if backend didn't send), it could guess what backend it is connected with and use the respective trace API if available. Downsides of this are that it would increase the size of ethers.js, so this instead would make sense to exist as an ancillary package, and those interested could use it.
@ShivamDev31 Hi, It is due to contract code error or improper call/invalid parameters (always failing transaction) in most cases, please review your code, this is not due to ethers.js, even if you use other lib like web3, you will get same error.
@zemse then it makes sense. I'll try it out too.
@aksdevac you are right. I figured out it was due to my fault at one place or the other as the ABI had changed. I just figured it out later as the revert messages were not clear as they were clear in localhost env.
Things are working fine now. Just 1 more thing before I close this issue.
As you can see in the screenshot above the Gas Price is always 1 GWEI and Gas Limit is too high. Is it some issue from my end or its a testnet issue?
@ShivamDev31 Heya! I don't quite understand. What do you mean by the gas price is always 1 GWEI and the gas limit is too high? The gas price and gas limit are not really related other than they are both used so compute the fee of a transaction...
Most helpful comment
If you are passing a lot of gas and still if you get this, it probably means that
always failing transactionis the case. You can look for any require statemenets in your contract that might be causing the fail?