Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode/Encode event topics for large types #434

Closed
goodjoon opened this issue Apr 14, 2016 · 39 comments
Closed

Decode/Encode event topics for large types #434

goodjoon opened this issue Apr 14, 2016 · 39 comments
Assignees
Labels
0.x.x Bug Addressing a bug

Comments

@goodjoon
Copy link

goodjoon commented Apr 14, 2016

Watching event with string argument cause "Uncaught BigNumber Error: new BigNumber() not a base 16 number: " Exception.

Below is my Contract code to test event.

contract StringTest {
    string stringHolder;

    event stringChanged(string indexed changedString);

    function setString(string _string)  {
        stringHolder = _string;

        stringChanged(stringHolder);
    }

    function getString() constant returns (string) {
        return stringHolder;
    }
}

and Javascript side which runs on Chrome browser.

var Web3 = require('web3');
var web3 = new Web3();
web3.setProvider(new Web3.providers.HttpProvider("http://10.77.135.188:8547"));

var abi = [{"constant":false,"inputs":[{"name":"_string","type":"string"}],"name":"setString","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"getString","outputs":[{"name":"","type":"string"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"changedString","type":"string"}],"name":"stringChanged","type":"event"}];

var code = "<..... Contract Byte Code from online contract editor ...>";

var sender = "0x02C370C2B797B2E71AD79BD2D9810534F55A4F08";
web3.personal.unlockAccount(sender, "1111");

var Contract = web3.eth.contract(abi);
console.log("Deploying Contract..");
Contract.new({ "from":sender , "data" : code, "gas" : 4700000}, function (error, contract) {
    if (contract.address != undefined) {
        console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);

        // Register Event Listener
        contract.allEvents(function(error, log) {
            if (error != undefined) {
                console.error(error);
                return;
            }

            console.log("[Event Coming]", log);
        });

        // Send setString() message transaction
        contract.setString("I'm Testing String Event Log", {"from":sender,"gas":4000000});
        console.log("Contract Creation and Sending Message Done. Just waiting for event...");
    }
});

then I get result as below.

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Deploying Contract..
Contract mined! address: 0x6c3cedb24ad719d2c32bd3bbdb83bd44a52dce02 transactionHash: 0x569b9170ce13a9a1781592e12e4ecdfad976a6c036308af216ed5a221ee11436
Contract Creation and Sending Message Done. Just waiting for event...
Uncaught BigNumber Error: new BigNumber() not a base 16 number: 
        raise    @    bignumber.js:1177
        (anonymous function)    @    bignumber.js:1165
        BigNumber    @    bignumber.js:212
        formatOutputString    @    formatters.js:217
        (anonymous function)    @    type.js:237
        SolidityType.decode    @    type.js:238
        (anonymous function)    @    coder.js:219
        SolidityCoder.decodeParams    @    coder.js:218
        SolidityEvent.decode    @    event.js:147
        AllSolidityEvents.decode    @    allevents.js:66
        (anonymous function)    @    filter.js:118
        onMessage    @    filter.js:117
        (anonymous function)    @    requestmanager.js:259
        (anonymous function)    @    requestmanager.js:258
        request.onreadystatechange    @    httpprovider.js:114

web3.js = 0.16
Geth = 1.3.5
Solidity Editor's Solidity version = v0.3.1

And I found another article about this issue also.
(http://ethereum.stackexchange.com/questions/1741/what-does-the-web3-bignumber-not-a-base-16-number-error-mean#)

It should be fixed.

@pjworrall
Copy link

Did you resolve this? I have had a similar error when I have not had something right elsewhere. For example web3.personal.unlockAccount reports that it isn't implemented. I am informed that web3 does not give you a means to create sessions for accounts.

@se3000
Copy link

se3000 commented Apr 26, 2016

Any update on this?

@se3000
Copy link

se3000 commented Apr 27, 2016

I saw this when my node 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. This may arise from other issues, but these seem like two common scenarios that could cause this error.

@frozeman
Copy link
Contributor

@se3000 thanks, We should catch that properly on web3.js and don't try to parse it.

@frozeman frozeman added the Bug Addressing a bug label Apr 28, 2016
@frozeman frozeman added this to the 1.0 milestone Apr 28, 2016
@sharkfisher
Copy link

The BigNumber() is not a base 16 number error can happen in many cases, yet the causes are not necessarily the same.
I believe the original post's issue is with using Events that index on "string" types, which I'm running into as well. If my contract event marks a "string" type as "indexed", i get the same error. But if I restrict the "indexed" keyword to only "address" type, I'm fine.
I'm trying to find documentation on what data types can be "indexed" in a contract event, but to no avail. My gut feeling is anything that can be parsed as a number (address, integers etc) might be OK.
I don't think blockchain synching is the issue here.

@sharkfisher
Copy link

In the Solidity doc, it seems to indicate that strings CAN be indexed.

If arrays (including string and bytes) are used as indexed arguments, the sha3-hash of it is stored as topic instead.

So maybe this is a bug on events? Can someone confirm?

@bkrem
Copy link

bkrem commented Jul 10, 2016

Thank you @sharkfisher for pointing to the indexed keyword. Had the same BigNumber error but worked as expected when omitting it from the event params.
Seems strangely inconsistent, especially with the above mentioned implication of being able to use indexed on string in the docs.

@coeniebeyers
Copy link

Just in case this helps someone, removing all node_modules and doing a npm install solved this issue for me.

@hedugaro
Copy link

Any update on this?
I need to work with events returning strings...

@phleemac
Copy link

phleemac commented Aug 29, 2016

I too is just hit by this bug. I think the problem is Web3 is parsing indexed event arguments of dynamic types (e.g. String, bytes, array) incorrectly. According to http://solidity.readthedocs.io/en/latest/contracts.html#events, dynamic types are encoded as sha3 hash, but Web3 parse them as is (e.g. String).

@ngotchac
Copy link

Yes, Web3 is wrongly parsing indexed array types as is (strings, bytes, array). The returned value is in fact a SHA3 hash of the real value...

@daithi-coombes
Copy link

Same issue. Wasn't using events or setting index, simple constant returns(string).. and web3 was reporting BigNumber() not a base 16 number.

Resetting testrpc, then redeploying with truffle migrate --reset solved the issue.

  • TestRPC v2.0.9
  • Truffle v2.0.8
  • Web3 0.16.0

@maraoz
Copy link

maraoz commented Oct 20, 2016

I can confirm I can reproduce this error with indexed string arguments for events.

I created a test contract with the event:

event TestEvent(string song);

and I can correctly watch it and handle it's occurrence. If I change it to:

event TestEvent(string indexed song);

It throws:

BigNumber Error: new BigNumber() not a base 16 number:

@balamuraliv
Copy link

Any update ,I am getting this error .I am using Geth
Version: 1.4.12-stable-421df866
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.7.1
OS: darwin
GOPATH=
GOROOT=/usr/local/Cellar/go/1.7.1/libexec
Please let me know what needs to be done.

@bellaj
Copy link

bellaj commented Nov 11, 2016

try to sync your chain

@balamuraliv
Copy link

Hi Bellaj,
thanks for the reply ..could you please let me know how to sync the chain ..I am using DEV net .
Thanks in advance.
Regards,
Bala

@johnmiroki
Copy link

Same issue, when using an event with string typed indexed, something like his:

contract Index1 {
  event IndexReceived(
    address indexed _from,
    string indexed _content
  );

  function save(string content){

    IndexReceived(msg.sender, content);
  }
}

Then, error fires when I do Index1.deployed().allEvents().get(callback))

@catageek
Copy link

Same issue, but curiously only when removing 'indexed':

event NewRequest(bytes16 indexed hash, uint salt, string hint, uint max_length); is OK
event NewRequest(bytes16 hash, uint salt, string hint, uint max_length); is NOK

@D-Nice
Copy link

D-Nice commented Feb 2, 2017

Ran into same issue, had to remove the 'indexed' keyword from a 'string' type in an event to workaround this. Hoping for an eventual fix of this.

@markya0616
Copy link

Any updated about this issue? We also encountered the same issue in my side....

@pjworrall
Copy link

pjworrall commented Feb 6, 2017 via email

@FlamingFlowair
Copy link

FlamingFlowair commented Feb 21, 2017

Hi there, had thi problem on a private blockchain.
The "wait for sync" advice worked perfectly.
Thanks :)

@clowestab
Copy link

This issue still persists in the latest version of web3.js (0.19.0).

Working with a third party contract, can anyone provide any insight into what causes this and how it can be fixed?

@bellaj
Copy link

bellaj commented Jun 4, 2017

@clowestab this error is raised by different causes. you might provide more details. sometimes it is due to an error in the dapp's web3js code.

@fleasharp
Copy link

fleasharp commented Jun 7, 2017

As others have stated; you can re-synce your blockchain to work around this. In my case; I just restarted testrpc; redeployed my contract and my string worked.

@EasonWang01
Copy link

Are this bug has been considered?Because this still happen after 1 year.

@peterbitfly
Copy link

It seems to be better handled in the new 1.0.0 beta, it still does not parse the string correctly but it returns a proper error message.

@xyrobo
Copy link

xyrobo commented Jul 31, 2017

nobody solve this problem?

@LaceLetho
Copy link

I got the same exception caused by an out of index error. Seems Solidity can't clearly describe the cause of the error

@frozeman frozeman added the Enhancement Includes improvements or optimizations label Aug 10, 2017
@frozeman frozeman modified the milestones: 1.1, 1.0 Aug 10, 2017
@frozeman
Copy link
Contributor

frozeman commented Aug 10, 2017

Certain parameters can't be decoded when they are indexed event parameters. As they are stored in the topic slot of 32bytes, solidity tightly packs them and sha256 them.
Web3.js currently doesn't support that, thats why these errors.

Im working on adding the decoder detection, as well as properly encoding it so that you can "watch" for those index params.
Any help is welcome. The tests can be found here: https://github.com/ethereum/web3.js/blob/1.0/test/eth.abi.decodeLog.js

Reminder: arrays, strings and bytes are tightly packed and hashed, all static types are kept as is

@frozeman frozeman changed the title Event with string argument cause "BigNumber() not a base 16 number" Exception Decode/Encode event topics for large types Aug 10, 2017
@chalpat
Copy link

chalpat commented Aug 12, 2017

How to use string and address as indexed in events? I am using geth 1.6.6-stable, web3 api 0.20.1. Still facing the same issue. Does any other version solves the issue? Please let me know.

@farhankhwaja
Copy link

I got the same issue today, but when I replayed the event watcher to start again from the a starting block everything went perfect. Sometimes i get this issue, sometimes I don't. Can this be an issue of blockchain sync??

@frozeman any updates on this would help me greatly.

@JackPickering
Copy link

I believe this may also be an issue with the json files that the build cycle creates. This error comes up for me seemingly randomly however, if I delete all of the .json files (except migrations.json) in the build folder and re-run compile/migrate in the truffle console then everything runs smoothly.

@glitch003
Copy link

Hi, I just wanted to chime in and let people know that the bug of web3 being unable to decode an indexed dynamic type from an event is fixed in web3 1.0 beta 18

Simply upgrading to 1.0 fully fixed this for me.

@findlabjie
Copy link

@glitch003 web3.js 1.0 isn't released ,how to upgrand to 1.0 ? thank you

@glitch003
Copy link

@kyriediculous
Copy link

kyriediculous commented May 31, 2018

This issue still persists in web3 0.20.x .
Ran into it today when trying to parse events with an indexed string in my unit tests.

Note : The error only happens on indexed strings in events !

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added the 0.x.x label Aug 15, 2018
@KEHSIHBA-IGAYT
Copy link

This issue still persists on 0.4.24 as well. I am not even using "indexed" string parameters.
I guess for syncing, I needed to restart the nodes but when I executed stop.sh, it gave me this:
"bootnode : no process found", "constellation : no process found".
Then I tried starting the nodes with raft-start.sh, and now I cannot attach my geth console. It gives some connection error.

@nivida nivida removed the Enhancement Includes improvements or optimizations label Nov 29, 2018
@nivida
Copy link
Contributor

nivida commented Mar 25, 2019

Version 0.20.x got his last maintenance release with v0.20.7. Please update your code to the latest 1.0 version of Web3.js. Further details about the current project state are explained in the release announcement of version 1.0.0-beta.38.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.x.x Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests