2

This is my sample contract..

pragma solidity ^ 0.4.15;

contract Sample{

  struct Info
  {
    address pubKey;        //key
    bytes32 Id;
  }

  mapping(address => Info) public userMap;

  // Registration
  function register(bytes32 orgId, address pubKey) public returns(bool){
    if (pubKey == 0x0 || orgId == 0x0 ) {
        revert("Pub Key & Org Id are mandatory");
    }
    if (userMap[pubKey].pubKey == pubKey) {
        revert("User already exists");
    }
    userMap[pubKey].pubKey = pubKey;
    userMap[pubKey].orgId = orgId;
    return true;
  }
  //getting the given Details
  function getUser(address pubKey) public returns(bytes32 orgId){
    orgId = userMap[pubKey].orgId;
  }
}

I have to handle the message returning from the revert() in the api (node.js). Whether will I get this message in the transactionReceipt of the corresponding transaction like web3.eth.getTransaction(txhash) or where can I read the above message?

3

Short story is that it's impossible to read the return data from the transaction receipt. This is true for both the success return data and the revert reason. The only way you can really do this currently is by logging an event notifying the front end of an error and returning false instead of reverting.

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.