I have a smart contract with this simple function:

function addUser( string memory _username, string memory _nome, string memory _cognome, string memory _email) public  isOwner() {
    require(bytes(_username).length > 0 , "Username vuoto");
    require(bytes(_nome).length > 0 , "Nome vuoto");
    require(bytes(_cognome).length > 0 , "Cognome vuoto");
    require(bytes(_email).length > 0 , "Email vuota");
        userCount ++;
        users[userCount] = User(userCount, _username, _nome, _cognome, _email);
        emit UserAdded(userCount, _username, _nome, _cognome, _email);
        **revert("User already exists");**


I interact correctly with its in javascript using truffle

App.partecipazioneContest = await App.contracts.PartecipazioneContest.deployed() 

try {
  await App.partecipazioneContest.addUser(username, nome, cognome, email);

} catch (error) {

Is there any way to get the reason message? (in this case "User already exists").

In my catch block I get an error but I can not find the way to get the revert error message. (emit event doesn't work).

(Update) The error that I catch:

errorStatusError: Transaction: 
0x247eeddd17eccae3376aea92587fd395d46202d78bb3aa0a9d4a0b05607de7e3 exited 
with an error (status 0).
Please check that the transaction:
- satisfies all conditions set by Solidity `require` statements.
- does not trigger a Solidity `revert` statement.
  • You should be seeing the revert-message, unless the contract function has reverted for something else. What Truffle version are you using? – goodvibration Jul 2 '20 at 17:26
  • @goodvibration I'm using Truffle v5.1.32 . I post the error that i get. However I am sure my function revert because on Ropsten log there is the correct message. I need to catch the same error in my client – alfo888_ibg Jul 3 '20 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.