0

I have a smart contract and on my web interface I'd like to display the 5 latest transactions. Currently these include any ether being sent to my contract which are retrieved using web3.eth.getTransaction() and transaction hash.

However, I have a variable leaf which any address is allowed to buy, this is logged using an event function. Can the number of leaf purchased be logged and retrieved using the transaction hash?

EDIT: So, I've managed to retrieve all the events using the allEvents() functions. Unfortunately, it returns two different structured objects:

The first one, returns this, which contains the args variable - as expected:

  • Event: event depositedFunds(uint amount, uint newBalance);
  • Returned object: {logIndex: 0, transactionIndex: 0, transactionHash: "0x82b69effb105ef1998fefdbf47d471c54c33a5b3b6b6462da33ecb790b2ce410", blockHash: "0xd16a7efac06f35725ae75bc3bca5a862a2847a94c2f2084c6a6f4d22c71958ec", blockNumber: 3, …}

The second, which is logged when the desired event is called returns this, which does not contain the args variable:

  • Event: event leafWasPicked(uint leavesLeft, uint numberTaken);
  • Returned object: {logIndex: "0x0", transactionIndex: "0x0", transactionHash: "0xbfd6a21c6d782e18f7636be9895849de8333678f5d7d28a0a406575988e7d653", blockHash: "0x765264a7c21d9c088adfc70a15a69a7b3f3c0408eb3758390bda2596d47aa48f", blockNumber: "0x5", …}

Why are both of these different?

4
  • I would suggest using Events and then use a filter to get the latest 5 transactions and also getting the leaf purchused using events. More infor how to get the log (event) here: github.com/ethereum/wiki/wiki/JavaScript-API#web3ethfilter Commented Nov 28, 2017 at 13:04
  • I've tried to implement your solution but here's the error when fetching events using the allEvents functions: When it return this: {logIndex: 0, transactionIndex: 0, transactionHash: "0xc88bc5a0c318a9cc74d8f", blockHash: "0xea475411b5b18be2b7e5a0d7ae231dc1329", blockNumber: 31, …} the event is correctly logged inside it. But when the event function that I actually need is called it returns this which does not contain log information: {logIndex: "0x0", transactionIndex: "0x0", transactionHash: "0x7035283a8eafacb754399110be2", blockHash: "0xf9162db97c83e68c4a777", blockNumber: "0x21", …}
    – Charles
    Commented Nov 28, 2017 at 15:05
  • For clarity, hashes were shortened to match max word count.
    – Charles
    Commented Nov 28, 2017 at 15:06
  • check how you are calling the events or creating the event you need. It should work Commented Nov 29, 2017 at 11:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.