In contract, there are always some storage change like token transfer. I want to detect the token transfer event. Token always store in contract mapping struct. So how can i detect the mapping change or the variables change in contract storage and recognize this is a token change event?


You want to detect this from outside the contract, right? For example in an application using web3.js?

In the contract, create an event with the information you want and call it when the token transfer happens.

See here for how you can then listen for that event: https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-events

  • Actually, i want parse all those token transfer in blockchain. And the method i think is parse from the event logs. If there is no event be set while coding, maybe parse this kind of balance change can be really hard – rong jialei Aug 1 '16 at 5:58

You can use this script:

function checkAllBalances() { 
  var i =0; 
  eth.accounts.forEach( function(e){
    console.log("  eth.accounts["+i+"]: " +  e + " \tbalance: " + web3.fromWei(eth.getBalance(e), "ether") + " ether"); 

taken from this thread.


From inside the contract you can't. The only block variables you have access to are mentioned here.

  • Thanks for you answer. I want parse all the token balance in contract. I found it can be obtain in etherscan.io, so i am confused how to get it. – rong jialei Aug 1 '16 at 7:39
  • etherscan.io is used for the main net meaning that balances have an equivalent in real currency. Have a look at their API: etherscan.io/apis – Sebi Aug 1 '16 at 7:52
  • Yes, i know that. I want do the same api with etherscan.io. And got some problem. – rong jialei Aug 1 '16 at 8:48

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.