Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txPromise.wait() reverts but transaction is successfull. #564

Closed
Amxx opened this issue Jul 23, 2019 · 9 comments
Closed

txPromise.wait() reverts but transaction is successfull. #564

Amxx opened this issue Jul 23, 2019 · 9 comments
Assignees

Comments

@Amxx
Copy link

Amxx commented Jul 23, 2019

The transactions I try to submit are successful (kovan) but the code fails.

Here is the code with extensive logs

lotteryID    = 77;
ticketPrice = 20;

token
.connect(wallet)
.approveAndCall(lottery.address, ticketPrice, ethers.utils.defaultAbiCoder.encode(["uint256"], [lotteryID]))
.then(txPromise => {
	console.log("[#2] txPromise:", txPromise);
	const w = txPromise.wait();
	console.log("[#3] w:", w);
	w
	.then(tx => {
		console.log("[#4] tx:", tx);
		resolve(tx);
	})
	.catch(e => {
		console.log("[#5] e:", e);
		reject(e);
	});
})
.catch(e => {
	console.log("[#6] e:", e);
	reject(e);
});

And the logs:

#2] txPromise: { nonce: 188,
  gasPrice: BigNumber { _hex: '0x77359400' },
  gasLimit: BigNumber { _hex: '0x03c9bc' },
  to: '0xc57538846Ec405Ea25Deb00e0f9B29a432D53507',
  value: BigNumber { _hex: '0x00' },
  data:
   '0xcae9ca510000000000000000000000005ebd616389e5bc21fbbe570a435f081991b9f9f3000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003',
  chainId: 42,
  v: 120,
  r:
   '0x524e6d59cb1a4d7c12b20ddfd1d35e0e95b84760efa74245d5bcb91b1b283808',
  s:
   '0x6b064bd01edad20bbd882befe8fe213b98e367808bcfd4f2dbfe3a2fde773093',
  from: '0xF037353a9B47f453d89E9163F21a2f6e1000B07d',
  hash:
   '0x90b60adad63bafc6dda2ebcf8c7016ea919364344ac9386aa9932fe517102fef',
  wait: [Function] }
[#3] w: Promise { <pending> }
[#5] e: { Error: insufficient data for uint256 type (arg="value", coderType="uint256", value="0x", version=4.0.33)
    at Object.throwError (/home/.../node_modules/ethers/errors.js:76:17)
    at CoderNumber.decode (/home/.../node_modules/ethers/utils/abi-coder.js:403:20)
    at /home/.../node_modules/ethers/utils/abi-coder.js:688:32
    at Array.forEach (<anonymous>)
    at unpack (/home/.../node_modules/ethers/utils/abi-coder.js:680:12)
    at CoderTuple.decode (/home/.../node_modules/ethers/utils/abi-coder.js:807:22)
    at AbiCoder.decode (/home/.../node_modules/ethers/utils/abi-coder.js:956:61)
    at _EventDescription.decode (/home/.../node_modules/ethers/utils/interface.js:190:60)
    at Interface.parseLog (/home/.../node_modules/ethers/utils/interface.js:375:31)
    at /home/.../node_modules/ethers/contract.js:219:65
  reason: 'insufficient data for uint256 type',
  code: 'INVALID_ARGUMENT',
  arg: 'value',
  coderType: 'uint256',
  value: '0x' }

The ABI for approveAndCall is

{
      "constant": false,
      "inputs": [
        {
          "name": "_spender",
          "type": "address"
        },
        {
          "name": "_value",
          "type": "uint256"
        },
        {
          "name": "_extraData",
          "type": "bytes"
        }
      ],
      "name": "approveAndCall",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
}

I just don't get what I'm doing wrong !

@ricmoo
Copy link
Member

ricmoo commented Jul 23, 2019

A transaction should almost always succeed, since all success means is that the network accepted the transaction. It does not know if the execution will succeed or revert, and it does not care. When you wait for the receipt (which is what .wait() does), it waits for the transaction to be mined, at which time code execution succeeds or reverts.

Do you have a link to the code? It seems odd to me to get that error. It seems like it is trying to parse an error, but there isn’t one to parse...

@ricmoo ricmoo added the investigate Under investigation and may be a bug. label Jul 23, 2019
@ricmoo ricmoo self-assigned this Jul 23, 2019
@Amxx
Copy link
Author

Amxx commented Jul 24, 2019

When I said that the transaction is successful I meant that the transaction is successfully mined.

Code is here:
→ scripts/main.js

@zemse
Copy link
Collaborator

zemse commented Aug 3, 2019

I am facing exact issue. .wait() is reverting. I understand that a transaction would be mostly always successful that's why I put an estimate instruction before the transaction instruction in try catch block so that estimate would revert.

let tx;
try {
    await timeswappersInstance.estimate.deposit(...Object.values(depositArguments));
    tx = await timeswappersInstance.deposit(...Object.values(depositArguments));
    console.log(tx);
    document.getElementById('add-funds-button').innerText = 'Waiting for deposit confirmation';
} catch(e) {
    document.getElementById('add-funds-button').innerText = 'There was a error.';
}

try {
    await tx.wait();
    document.getElementById('add-funds-button').innerText = 'Deposit successful. Submitting hash to Timeswappers server.';
} catch(e){
    console.log(e.message);
    document.getElementById('add-funds-button').innerText = 'There was a error.';
}

First try catch executes successfully, the second one fails. I checked with the tx hash on Rinkeby test net, transaction shows successfully mined.

Error that .wait() throws is:

Uncaught (in promise) Error: insufficient data for uint256 type (arg="amount", coderType="uint256", value="0x", version=4.0.11)
    at Object.n [as throwError] (ethers-v4.min.js:1)
    at e.decode (ethers-v4.min.js:1)
    at ethers-v4.min.js:1
    at Array.forEach (<anonymous>)
    at B (ethers-v4.min.js:1)
    at e.decode (ethers-v4.min.js:1)
    at t.decode (ethers-v4.min.js:1)
    at t.decode (ethers-v4.min.js:1)
    at e.parseLog (ethers-v4.min.js:1)
    at ethers-v4.min.js:1

@ricmoo
Copy link
Member

ricmoo commented Jul 5, 2020

@zemse Can you try this on v5? It looks like either an event is being emitted with insufficient data. This came up recently with contracts compiled on Solidity 4.x with the function marked as external (public works fine, but there is a bug in the 4.x compiler). Does that sound like it might be related?

@zemse
Copy link
Collaborator

zemse commented Jul 5, 2020

@ricmoo This is possible that it is related. Back then I didn’t observe the contract version. I was helping a colleague with ethers.js code (who was probably using 4.x Solidity)

I have been applying .wait() almost in all test cases that I write to verify logs. This is definitely not a problem with latest Solidity versions.

If anyone is getting this problem, if it’s possible for you to upgrade the compiler version and redeploy yiur contracts, you can probably get this solved by yourself.

However is there any workaround for those who have production contracts written in 0.4.x and want to replicate the .wait() utility?

@StillFantastic
Copy link

@ricmoo I having the same issue, here is the transaction: https://ropsten.etherscan.io/tx/0x7928c57dc5c49479867593b32f3e7816d89b506d8496e94e7a3afdb9b40a7bd6, its status is success but throws an Error: transaction failed error when wait.
The version I'm using is @nomiclabs/hardhat-ethers": "2.0.1"

@StillFantastic
Copy link

Maybe it's a problem from gas station network, since I'm using gsnProvider

@StillFantastic
Copy link

Never mind, not related to ethers

@zemse
Copy link
Collaborator

zemse commented Jun 30, 2021

I believe the OP was solved in 5.0.12 release (see #891 (comment), #992). If that's not the case please reopen.

@zemse zemse closed this as completed Jun 30, 2021
@ricmoo ricmoo removed the investigate Under investigation and may be a bug. label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants