Is there a known problem with parsing events containing strings in Truffle/Web3?
I'm using truffle with the following simple contract
contract Board
{
string foo;
event Shout();
event TextEvent(
string indexed text,
uint timestamp
);
function shout(string _text)
{
foo=_text;
Shout();
TextEvent(_text,now);
}
function getFoo() returns(string){
return foo;
}
}
When I call shout(_) foo is set correctly and a Shout event is triggered and I can listen to this without any problems.
var board = Board.deployed();
var shouts=board.Shout();
shouts.watch(function(error, result){
if (!error)
console.log("shout",result);
});
However when I watch for TextEvents with the following code
var board = Board.deployed();
var textEvent=board.TextEvent();
textEvent.watch(function(error, result){
console.log("callback");
if (!error) console.log("shout",result);
});
I get the following error which seems to be related to converting bytes32 into a string:
Uncaught BigNumber Error: new BigNumber() not a base 16 number:
So the question is how can you listen to events containing strings in Web3 without running into this error?
Best Answer
I saw this when my blockchain wasn't fully synced. The contract was expecting a string to be returned, but since that string hadn't been set yet it was returning null, which would blow up on parsing.
I believe the same thing could happen when pointing to an address that doesn't actually implement that API. If the fallback function doesn't return a string then you'll have trouble parsing a string.
Just make sure your blockchain is synced, and you're pointing to the right account.