2

I can obtain all event logs. My code is:

var contractInstance = contract.at("0x123456...789");
var transferEvents = contractInstance.allEvents({fromBlock:0, toBlock:'latest'});

and the output is:

{ address: '0xafe6851c1d9ee2e759acdee8cfc827e22a9ec5d7',
blockHash: '0xe5cdc4ae1e70ad4b4610a1f5a45fb3ff56bc3530f159ab0613ffeb33a7bf9c0a',
blockNumber: 1924935,
logIndex: 3,
transactionHash: '0x2e18ac5cb925b95ec609970e66d566623f446bc67bd0b72aac0a2ca6e96ef128',
transactionIndex: 4,
event: 'Transfer',
args:
 { from: '0xd94c9ff168dc6aebf9b6cc86deff54f3fb0afc33',
   to: '0x414755edffa43707f7d51600edf9ecbe57152a8a',
   value: [Object] } },

But i obtain get Transfer event data

var contractInstance = contract.at("0x123456...789");
var transferEvents = contractInstance.Transfer({fromBlock:0, toBlock:'latest'});

the output is empty.

Is there any problem in my code?

1 Answer 1

2

Try

var transferEvents = contractInstance.Transfer({}, {fromBlock:0, toBlock:'latest'});

Source: How do I retrieve the Voted events from The DAO



Answer to question in the comment

Q the return seems a long string contain all logs. How can i split them one by one?

(from the same link above) I firstly use JSON.stringify(...) to view the data:

> var theDAOVotedEvent = theDAO.Voted({}, {fromBlock: 1614771, toBlock: 'latest'});
undefined
> theDAOVotedEvent.watch(function(error, result){
  console.log(JSON.stringify(result));
});
...
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":true,"proposalID":"15","voter":"0xebbf5d7d649aedde2c27a8b850a2a3862595eb53"},"blockHash":"0x3d0e8b47fbb03727c72585fbe2fd5f25c69c03f2b832753567c2309f1ecb3b2a","blockNumber":1614808,"event":"Voted","logIndex":0,"transactionHash":"0x0060654808a2dee9710fa01e26adb46e77df03c17e453e8fddc8749269ffad92","transactionIndex":1}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":false,"proposalID":"11","voter":"0xebbf5d7d649aedde2c27a8b850a2a3862595eb53"},"blockHash":"0x607d940ebbbb17e6d5c3c8a871cd4783b271ddf71f4aeb83dbcdcaf8ce2154d9","blockNumber":1614812,"event":"Voted","logIndex":1,"transactionHash":"0x6b5cab6f7987d7283fdde051c76ace98c9f080bda6dbdf720689fc0c3958005b","transactionIndex":6}
{"address":"0xbb9bc244d798123fde783fcc1c72d3bb8c189413","args":{"position":false,"proposalID":"11","voter":"0xebbf5d7d649aedde2c27a8b850a2a3862595eb53"},"blockHash":"0x69be968ce90c7e910c149cc80ab1e5f2ae6bdb45f142ee0e6fa181be9d1e106e","blockNumber":1614812,"event":"Voted","logIndex":0,"transactionHash":"0x6b5cab6f7987d7283fdde051c76ace98c9f080bda6dbdf720689fc0c3958005b","transactionIndex":2}

...

Once you can see the data, you can reference each field, for example:

result.address
result.args
...
7
  • 1
    It works! So appreciate! Commented Aug 2, 2016 at 5:36
  • the return seems a long string contain all logs. How can i split them one by one? Commented Aug 2, 2016 at 6:02
  • See update to answer Commented Aug 2, 2016 at 6:08
  • I got it. I'm sorry because i'm not familiar with node.js. Sorry for the low level question. Commented Aug 2, 2016 at 6:25
  • 1
    Yup. That will give you the result.args values. Commented Jan 23, 2017 at 12:48

Your Answer

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

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