Aim: To log data from a smart contract.

Following function is written in accordance with low level interface to Logs in ethereum. However, due to lack of documentation, and being new in Solidity, I am not able to figure out how and where to get the logs.


 function addNewUser(address _userAddr, uint _amount) public {
        require(msg.sender == _userAddr); //only owner of lottery can create new Users
        uint256 id = users.push(User(_amount, _userAddr)) - 1;
        addressToUser[_userAddr] = id;
        NewUser(_amount, _userAddr); //event to FE (no return possible in BC edit functions)

When i call function on truffle's console following data is displayed:

Command: lot.addNewUserToLottery(24, 0x6330a553fc93768f612722bb8c2ec78ac90b3bbc);


{ tx: '0xcfd479f7493f215d3f4bac54ab6331fc2dfaea88784a0f543614e22c7092ccf8',
   { transactionHash: '0xcfd479f7493f215d3f4bac54ab6331fc2dfaea88784a0f543614e22c7092ccf8',
     transactionIndex: 0,
     blockHash: '0xdd0ebd3f560bd8ce143fe0a77e99818e9a072fa7b9afb79f4beca0363dfb5047',
     blockNumber: 110,
     gasUsed: 96578,
     cumulativeGasUsed: 96578,
     contractAddress: null,
     logs: [ [Object], [Object] ],
     status: '0x01',
     logsBloom: '0x00000000000000000000000000000000000000040000000000000000000000000000008000000000000080000000000000000000000000400000000000000000000000000800000000000000000000000000000000000000040000000000000000000000000000000000001000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' },
  logs: [] }


 develop:testrpc   Gas usage: 26981 +0ms
  develop:testrpc   Block Number: 117 +0ms
  develop:testrpc   Block Time: Sat Apr 14 2018 15:25:59 GMT+0530 (IST) +0ms
  develop:testrpc  +0ms
  develop:testrpc eth_getTransactionReceipt +1ms
  develop:testrpc eth_sendTransaction +6s
  develop:testrpc  +48ms
  develop:testrpc   Transaction: 0x2f901a79252860c2200cc2923eba859ea585922a844a1aae69ee0240fe4ae45d +1ms

Where are the logs printed? Am I missing something?

  • Few IDEs support logx currently and Events will be easier to use. Related: ethereum.stackexchange.com/questions/7139/… – eth Apr 15 '18 at 6:45
  • I did go through the attached post. It suggested using Events or use logx (giving a link to solidity documentation) . I couldn't get enough information on how to go about logx method, and my own trials were in vain. Hence, I have posted the question. I am using Truffle dev env. testrpc node and intellij IDE. – blockwala Apr 15 '18 at 11:33

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.