[Ethereum] Listen to blockchain events in js

contract-invocationeventsweb3js

I want all js clients to react on new event being stored to blockchain:

contract MainContract{
    event Evt(address indexed _sender,string jsn);
    function deposit(string jsn) returns (int256) {
        Evt(msg.sender, jsn);
    }
}

Here I expect watch callback to be executed.

    var contract = web3.eth.contract(abi).at("0xe45866ac5d51067ce292bc656c790e94ddcf0766");
    var myEvent = contract.Evt({},{fromBlock: 0, toBlock: 'latest'});
    myEvent.watch(function(error, result){
        console.log("on watch"); 
        console.log(arguments);
    });
    // this call saves event data successfully!
    contract.deposit('hello there',function (res) {
        console.log(arguments)
    });

But I don't see 'on watch' in my console.
Is this possible? How can I do this? Any example?

UPDATE: my best guess right now that this is metamask.io problem (https://github.com/MetaMask/metamask-plugin/issues/792)

UPDATE2: Looks like a bug in ethereum kernel, some people report same experience: https://github.com/ethereum/go-ethereum/issues/14670

Best Answer

I've solved my problem: I used wrong contract address. Note, that API wouldn't let you know that contract address is incorrect!

Related Topic