I am using JavaScript to run some tests on my solidity contract. Since solidity ^0.4.22 you can have a message in require such as:

function Hello {
    require(msg.sender == 0x001234, "msg.sender MUST BE 0x001234"); 

When writing tests in javascript I can use the contractName.methods.function to access functions from within the solidity contract. Any idea how I could access the message from require or to implement to test that this message is shown correctly?


You can modify this helper a little bit to check error.message should contain your message on the require


  • Thanks a lot! I also found another possibility, basically using a try/catch and identify the error. Now I am going to integrate the message as well :D
    – Iulian
    Sep 7 '18 at 14:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.