Working with this example, I've been attempting to utilise event watching from the web js api.

Window 1 (a testrpc instance with filled account):

testrpc -a 1

Window 2

geth attach rpc:http://localhost:8545

in javascript api (abi created from from contract here - should be copy-pastable):

var test1Contract = web3.eth.contract([{"constant":false,"inputs":[],"name":"getval","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"b","type":"uint256"}],"name":"multiply","outputs":[],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"msg","type":"string"},{"indexed":false,"name":"x","type":"uint256"}],"name":"event_res","type":"event"}]);
var test1 = test1Contract.new(
   {
     from: web3.eth.accounts[0], 
     data: '0x6060604052341561000c57fe5b5b60016000819055505b5b610144806100266000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806331b6bd0614610046578063c6888fa11461006c575bfe5b341561004e57fe5b61005661008c565b6040518082815260200191505060405180910390f35b341561007457fe5b61008a6004808035906020019091905050610097565b005b600060005490505b90565b80600054026000819055507f17f524ec61c4a04edbebf70ec28fc4c5588a19fb0284a3405a56802e7b034a3460005460405180806020018381526020018281038252601f8152602001807f7468652076616c7565206166746572206d756c7469706c79696e672069733a008152506020019250505060405180910390a15b505600a165627a7a72305820f6f4267cce3a4c3546e40d76cc21793361eb41f0ef656f9345b2f47de8c8d3100029', 
     gas: '4700000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })
var interface = [{"constant":false,"inputs":[],"name":"getval","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"b","type":"uint256"}],"name":"multiply","outputs":[],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"msg","type":"string"},{"indexed":false,"name":"x","type":"uint256"}],"name":"event_res","type":"event"}];
var testing = web3.eth.contract(interface).at(test1.address);
var event = testing.event_res(function(error, result) {
    if (!error)
        console.log(result.args);
    else
        console.log(error);
});
var result = testing.multiply.sendTransaction(5,{from : web3.eth.coinbase},function(err,result){
        if(err)
        console.log(err);
});

This returns

> [object Object]
[object Object]

Whereas I'm expecting, from the original question:

{ msg: 'the value after multiplying is:',
  x: { [String: '5'] s: 1, e: 0, c: [ 5 ] } }

Is there something obvious I'm doing wrong?

Note:

In the first window I get something like, with eth_getFilterChanges repeated:

...
eth_getFilterChanges
eth_getFilterChanges
eth_getFilterChanges
eth_getFilterChanges
eth_coinbase
eth_sendTransaction

  Transaction: 0x3d716c20e03d8fd7009f532102391c9e7c67f7447180cd180de03436de27e7d
3
  Gas usage: 0x6fee
  Block Number: 0x06
  Block Time: Thu Apr 06 2017 11:42:55 GMT+0100 (GMT Daylight Time)
eth_getFilterChanges
eth_getFilterChanges
...

After seeing this, I (partially) got around the problem by using JSON.stringify:

console.log(JSON.stringify(result.args));

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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