1

Hello awesome ethereum community, Need help in viewing the arguments under event. I am using event AnyException for error handling. I pass a string argument to my event in my solidity file. When I run the function, I would like to view the string argument passed to my event. Currently, I just see args: [Object] . How do I vew the argument in truffle console?

EventTest.sol

pragma solidity ^0.4.15;
  contract EventTest {
    event AnyException(string message);

    function testEvent(string s) public returns (bool) {
      if (keccak256(s) == keccak256("titu")) {
        AnyException("Invalid input: titu");
        return false;
      }
      return true;
    }
  }

Truffle console

truffle(development)> var et; EventTest.deployed().then(function(deployed){et=deployed;});
undefined
truffle(development)> et.testEvent("titu");
{ tx: '0xcc99eeacdf9cf83aa82e4a1284a35eac71abfad85d91564fbbb4f611b7f52d69',
  receipt: 
   { transactionHash: '0xcc99eeacdf9cf83aa82e4a1284a35eac71abfad85d91564fbbb4f611b7f52d69',
     transactionIndex: 0,
     blockHash: '0x81f8c761825b96985e222e713fa7e17f1cabee1a130ca7651e0f8e0f1ba72a12',
     blockNumber: 13,
     gasUsed: 24374,
     cumulativeGasUsed: 24374,
     contractAddress: null,
     logs: [ [Object] ] },
  logs: 
   [ { logIndex: 0,
       transactionIndex: 0,
       transactionHash: '0xcc99eeacdf9cf83aa82e4a1284a35eac71abfad85d91564fbbb4f611b7f52d69',
       blockHash: '0x81f8c761825b96985e222e713fa7e17f1cabee1a130ca7651e0f8e0f1ba72a12',
       blockNumber: 13,
       address: '0x1940ce494ecf457feefa4d6874542353db01bf9f',
       type: 'mined',
       event: 'AnyException',
       args: [Object] } ] }
  • 1
    logs is an array, so you can inspect logs[0], logs[1]. In this case, just logs[0]. args is an object. You can inspect it with something like logs[0].args. You hope to see named arguments, so you could logs[0].args.oneProperty. – Rob Hitchens - B9lab Nov 26 '17 at 17:14
3

Thank you, @Rob Hitchens for the tip. Here is the solution by printing the json argument returned on the console.

truffle(development)> var et; EventTest.deployed().then(function(deployed){et=deployed;});
undefined
truffle(development)> et.testEvent("titu").then(function(ret){console.log(ret.logs[0].args.message);});
Invalid input: titu

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.