Web3.js: Web3 doesn't return custom required message

Created on 22 Jan 2020  ยท  16Comments  ยท  Source: ChainSafe/web3.js

Hi

When we have a revert in a transaction, web3 throws an error, and the error message contains this revert reason.

This error happen because i have a require inside my contract, so it is correct. So, i have a question: I can't get the custom message?

For example, if i have this require below:

function functionExample( uint256 _number) public returns (bool) { require(_number>10,"Number need to be bigger than 10"); }

When i send a number, for example, 8 (<10, so require revert the transaction), and i`m receiving this return:

{ Error: Transaction has been reverted by the EVM: { "blockHash": "0x4370ed0ddd1f121377ea336223050e760a70c7713a275639bc890e8857c3ba99", "blockNumber": 5833233, "contractAddress": null, "cumulativeGasUsed": 391416, "from": "0x3e31b2a2784fdf3b03b4401c53de19063f4a512e", "gasUsed": 24055, "logs": [], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": false, "to": "0xb0345348c912d7856fb28cd6f7804c7dde339654", "transactionHash": "0x9bbde7f847e442fe67f5c4bac60996435167da993d320176f0efd302130778ed", "transactionIndex": 2 }

Is it possible to receive the custom message? I mean, this message: "Number need to be bigger than 10".

This is so crucial for all contracts, and until now, i cant get this value...

Node: v10.15.3
Web3.js:
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]
OS: MacOS

1.x support

Most helpful comment

I also need an example, for me it seems this option does nothing

All 16 comments

@dzabeu Thanks for opening this issue! We have added the possibility to get the revert message of a transaction with version 1.2.5-rc.0. This version will get released as a production version on Thursday if there is no show-stopper until then. You are able to activate the transaction revert handling with defining the web3.eth.handleRevert option to true. The related documentation can currently be seen here and will be published on Thursday as well.

Hi @nivida !!

I just downloaded the new version [email protected], 10 minutes ago. This version doesn't have the improvement?

I put on my topic the web3 version that i have in my project
โ””โ”€โ”€ [email protected]

Tks

@dzabeu Thanks for commenting here again! I've tested it and this is actually the case. The 1.2.5-rc.0 tag here on GitHub, the related release branch, and the working branch 1.x do have those improvements included but not the published packages on npm. We apologize for the confusion and will fix it (publish a rc.1 version) asap.

Nice, tks you @nivida . This should be the problem, because i have used npm command to update the web3 version.

Do you alert us about this update by this topic? How can i check the moment that i could use this new functionality?

@dzabeu Thanks for your patience! I've tested it locally in an empty testing project and was no longer able to reproduce the issue. As it looks like does the package-lock of your project overwrite the web3-eth: 1.2.5-rc.0 dependency to download the 1.2.4 version of it.

I have deleted my package/package-lock.json and reinstall everything. But didnt work yet...

I told me that i need to use this command. Do you have some example to help?
web3.eth.handleRevert = true;

Tks!

Which version of the web3-eth package does get installed? The possibility is here that truffles package-lock is enforcing another version.

@nivida , only 1.2.5-rc.0:

npm list web3
โ””โ”€โ”€ [email protected]

Do you have an example to implement the command?

Note: The contracts were deployed on Rinkeby network.
Using ganache, for example, it is working normally (even before the update top 1.2.5...)

Now, to deploy o ganache, i needed to install truffle-wallet-provider, and now i have two version:

โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

But anyway, it was not working when i was using only web3 1.2.5

I also need an example, for me it seems this option does nothing

@k06a

There are examples in the unit tests here.

Those tests succeed against both ganache-cli and a geth --dev client (see travis here).

Can you identify a difference between what's done there and your case?

I use [email protected] and still can not see a revert message.

try {
          web3.eth.handleRevert = true;
          this.result  = await this.contract.methods.addItem(
            this.ipfs_hash,
            product_amount_String,
            this.form.product_name,
            token_amount_String,
            this.form.metadata,
          ).send({ from: accounts[0], gas: 4e6, gasPrice: 1e6})
         .on('error', (err, receipt) => {
            console.log("err.message =",err.message);
            console.log("receipt =", receipt);
          });

} catch (err) {
        console.log("web3.eth.handleRevert =", web3.eth.handleRevert)
        console.error(err);
        console.log("err.message =",err.message);
}

web3.eth.handleRevert = true

err.message = Error: [ethjs-rpc] rpc error with payload {"id":8485727948832,"jsonrpc":"2.0","params":["0xf901cb13830f4240833d0900949eafc37a5d473c5c0c9532bcb54104dcf72ee28280b9016459a4a6bd00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000002e516d56464464736b35454c4e44727937596e616965526835785a4b71594c376674634663384b514c4178326d3652000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000271710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000822d45a0050a3ca0581633590c4869356707314ae2d2f78ef158289147b357b78ea95069a0183e78569153626421c161ae3499cd9f02ae154e93d9b18f50fe5a1df450a55e"],"method":"eth_sendRawTransaction"} [object Object]

err.signature = undefined
err.reason = undefined
receipt = undefined

I am using Ganache GUI v2.0.2 and if I run my code from remix, it manages to display the revert message.

Would be great to have one working example code snippet.

I'm not sure this issue should be closed. Facing the same as above, attributes do not exist, on 1.2.6.

Edit: spoke too soon. @svenmeyer @k06a @dzabeu not sure what your setup is, but I can see reason if I JSON.stringify the resulting error, whether in a try-catch or in .on('error', ...)

somehow remix as well as etherscan manage to get that information out of transactions, but I still haven't managed that with web3 ...
@jmahhh ok, thanks, I will give that a try

Hi everybody!

I found it, and the article said that this is not work when you try to use with "sendSignedTransaction" function, that is right?

I`m using sendSignedTransaction.... maybe this is the reason that didn't work to me.

link:

https://www.soliditydeveloper.com/web3-1-2-5-revert-reason-strings/

Was this page helpful?
0 / 5 - 0 ratings