Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

returnValues parsed incorrectly #3158

Closed
yuwiggin opened this issue Oct 25, 2019 · 5 comments
Closed

returnValues parsed incorrectly #3158

yuwiggin opened this issue Oct 25, 2019 · 5 comments
Labels
1.x 1.0 related issues Enhancement Includes improvements or optimizations

Comments

@yuwiggin
Copy link

yuwiggin commented Oct 25, 2019

Description

The value was wrong in a String field of the returnValues.

Expected behavior

Calling contract.events.Authorized({ fromBlock: 8806769 }, function(error, event) { console.log(event); })
should return

......
"returnValues":{"0":"GeekGit",......,"name":"GeekGit",......}
......

Actual behavior

But returned

......
"returnValues":{"0":"0xef563641eef48cfa4dddd5f98049665d481ac4507793218a74d393e836c49d67",......,"name":"0xef563641eef48cfa4dddd5f98049665d481ac4507793218a74d393e836c49d67",......}
......

Steps to reproduce the behavior

1. Import `web3`
2. Set the provider to `WebsocketProvider`, i.e. infura
3. Fetch the block
contract.events.Authorized({ fromBlock: 8806769 }, function(error, event) {
   console.log(event);
});   

ABI JSON

      "events": {   "0x6f7089ad02947bd25268f2724218c84efd1ec156c5ad2d3366599cae89ff71f9": {
          "anonymous": false,
          "inputs": [
            {
              "indexed": true,
              "internalType": "string",
              "name": "name",
              "type": "string"
            },
            {
              "indexed": true,
              "internalType": "address",
              "name": "owner",
              "type": "address"
            },
            {
              "indexed": false,
              "internalType": "address",
              "name": "from",
              "type": "address"
            }
          ],
          "name": "Authorized",
          "type": "event",
          "signature": "0x6f7089ad02947bd25268f2724218c84efd1ec156c5ad2d3366599cae89ff71f9"
        }

Versions

  • web3.js: 1.2.1
  • nodejs: v8.15.1
  • NPM: 6.9.2
@cgewecke
Copy link
Collaborator

Hi @yuwiggin

Your string event argument is indexed, so the output looks like it might be correct?

From the events section of the solidity docs

You can add the attribute indexed to up to three parameters which adds them to a special data structure known as “topics” instead of the data part of the log. If you use arrays (including string and bytes) as indexed arguments, its Keccak-256 hash is stored as a topic instead, this is because a topic can only hold a single word (32 bytes).

@yuwiggin
Copy link
Author

Thanks @cgewecke . So, it can't be fetched in any way?

@cgewecke cgewecke added the 1.x 1.0 related issues label Oct 27, 2019
@cgewecke
Copy link
Collaborator

@yuwiggin The fired event will contain the keccak256 hash, so if you know what the string is in advance, you can always synthesize it using web3.utils.keccak256(val) and compare the emitted value with a pre-computed hash.

But often strings are being used for arbitrary, user-generated values...

Incidentally, it's not possible to set an event filter for an indexed string by the computed hash either - you have to do that manually in the event handler if it's helpful for your use case.

@nivida
Copy link
Contributor

nivida commented Oct 28, 2019

@cgewecke I will back-port this PR to the 1.x branch #3061

@nivida nivida added the Enhancement Includes improvements or optimizations label Oct 28, 2019
@cgewecke
Copy link
Collaborator

Closing in favor #344

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.x 1.0 related issues Enhancement Includes improvements or optimizations
Projects
None yet
Development

No branches or pull requests

3 participants