Reputation: 41
I am having trouble displaying the error message from the smart contract's require method in my Python console. I am using the web3.py module to interact with the contract.
Here is the smart contract code:
function burn(uint258 amount) public returns(bool){
require(balance[msg.sender]>=amount, "Not enough balance to burn");
...
}
Calling this method trying to trigger the require restriction does nothing in the console. Checking on etherscan the transaction is not completed (which is the desired behaviour). I found some solutions online about Remix, but I want the error message to be displayed in my python code.
Is the error message encrypted in some response like the hash of the transaction, or is there another way to get the message ?
Upvotes: 2
Views: 492
Reputation: 83788
To get the revert reason of a transaction, you can use fetch_transaction_revert_reason function from web3-ethereum-defi library.
Upvotes: 1