0

I am trying to listen to an event on rinkeby test which I run locally. Every thing works fine when my argument is int such as event EventTester(int values); When I change the event argument to string (it is not indexed) it does not work and I do not see the log. event EventTester(string values); . Any idea why? I do not see the Events Log tab when I check the transaction on https://rinkeby.etherscan.io.

Thanks

var fs = require('fs');
var Web3 = require('web3');
var util = require('ethereumjs-util');
var tx = require('ethereumjs-tx');
var lightwallet = require('eth-lightwallet');
var txutils = lightwallet.txutils;
var web3 = new Web3(
    new Web3.providers.HttpProvider('http://localhost:8545')
);
var address = '0x.....';
var key = '';
var bytecode = '6060...90029';
var interface = [{"constant":false,"inputs":[{"name":"input","type":"string"}],"name":"getOut","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"values","type":"string"}],"name":"EventTester","type":"event"}]

function sendRaw(rawTx) {
    var privateKey = new Buffer(key, 'hex');
    var transaction = new tx(rawTx);
    transaction.sign(privateKey);
    var serializedTx = transaction.serialize().toString('hex');
    web3.eth.sendRawTransaction(
    '0x' + serializedTx, function(err, result) {
        if(err) {
            console.log("ERROR HAPPENED:" +err);
        } 
    });
}

var contractAddress = '0x...';

strInterface='[{"constant":false,"inputs":[{"name":"input","type":"string"}],"name":"getOut","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"values","type":"string"}],"name":"EventTester","type":"event"}]'
abiDefinition = JSON.parse(strInterface)
myContract = web3.eth.contract(abiDefinition)
var contractInstance = myContract.at(contractAddress)

var txOptions = {
    nonce: web3.toHex(web3.eth.getTransactionCount(address)),
    gasLimit: web3.toHex(700000),
    gasPrice: web3.toHex(10000000000),
    to: contractAddress
};
var rawTx = txutils.functionTx(interface, 'getOut', ["hi"], txOptions);
sendRaw(rawTx);
2
  • Can you share the code? Oct 11, 2017 at 17:51
  • The code is very straightforward pragma solidity ^0.4.0; contract SimpleContract { event EventTester(string values); mapping(address => uint) callers; function SimpleContract() public{} function getOut(string input) public { EventTester(input); callers[msg.sender] +=1; } } The listener is event.watch(function(error, result){ if (!error){ console.log(result); }else { console.log('Error happened') } }); If you change string to int everything works well. Oct 11, 2017 at 18:24

2 Answers 2

0

I just gave it a try on Ropsten and seems to be working. Here's the transaction: https://gist.github.com/pabloruiz55/d73fabb23677f146c58d8c4d3950c0fa

You can see on the logs I sent a string "hola".

The code I used is exactly the same you wrote, tested it on Remix.

(Could not test it on Rinkeby as I just run out of Ether, but if you send me some, I'll gladly give it a try: 0x0fC20E774EA6674087494a36F8F8f09a4Ee3a131)

Update: Working fine on Rinkeby as well. https://rinkeby.etherscan.io/tx/0x5cf1cfd9c401b9b2d2c0d7a7d967f50e33aaa9bf9cfc97afad9f90b247a93ee9#eventlog

Here's a screen capture of Remix, just in case. enter image description here

3
  • It is really strange that it worked there. I sent you the ether. Please let me know. Thanks Oct 11, 2017 at 18:56
  • Works well on Rinkeby. Uploaded a screenshot of Remix above, just in case, so you can compare to what you are doing. @user5908755 Oct 11, 2017 at 19:02
  • if you do not mind, can you share the code that sends the transactions. I am using node to submit my transaction. I tried to the same contract you created and still does not work. Maybe my js code has an issue with strings (and not with int lol). I edited the original post to include my code Oct 11, 2017 at 19:28
0

If this is not a constraint to use web3, I suggest you to use it to call the method, that will avoid you lot of common errors (already resolved in the wrapper).

with web3@^0.20.6:

contractInstance.getOut.sendTransaction('hi', (err, result) => {
  if (err) {
    console.error(err);
  }

  console.log(result);
});

with web3@^1.0.0

contractInstance.methods.getOut('hi').send({ from: address }).then((result) => {
  console.log(result);
})
.catch((err) => {
  console.error(err);
});

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.