Code Monkey home page Code Monkey logo

event-hashes's Introduction

event-hashes

This is a minimal web utility to calculate the keccak256 hashes of the normalized event signatures of all the events in a Solidity code block. This hash can then be used with indexers like Etherscan to search for specific logs in the EVM history.

Warning

Known issues:

  • This tool won't work with user-defined value types. For events that include these types, you must manually convert the user-defined value type into its equivalent primitive type.
  • anonymous events do not log the hash of the event signature, so this tool is not useful for searching for anonymous event logs.

Also check out this gist to copy all the code blocks at once from an Etherscan smart contract code page; you can then directly paste the copied code into this tool to quickly parse all the events.

Example

Demonstration of the event-hashes web UI hashing the ERC-20 Transfer event.

Given the standard ERC-20 Transfer event:

event Transfer(address indexed _from, address indexed _to, uint256 _value)

The tool will normalize the event signature (i.e., remove spaces, input names, and extraneous keywords):

Transfer(address,address,uint256)

Then calculate the keccak256 hash of the UTF-8 encoded bytes of the normalized signature:

0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

This hash may then be used in another tool to filter a smart contract's logs, e.g. in Etherscan:

The "Events" page of a token smart contract on Etherscan, filtered to only the events matching the previously calculated Keccak-256 hash.

Features

Intelligently parse entire smart contracts

There's no need to manually extract the event signatures from the smart contract code. The tool will automatically ignore lines that don't contain event signatures.

Demonstration of the event-hashes web UI parsing an entire Solidity smart contract and ignoring lines of code that don't contain events.

Copy permalinks to code blocks

You can easily share links to events with other people. The entire codeblock is compressed and encoded into the URL fragment of the permalink and is decoded client-side (i.e., nothing is shared with a server).

For example, here's a permalink to the ERC-721 interface:

Demonstration of the event-hashes web UI showing the event hashes for the ERC-721 interface.

Useful table tools

The output is a normal, well-behaved <table> element. Accessibility and web browser functions should work as expected.

There are also utilities to download the table as a CSV file or copy it to clipboard, so you can easily export the table to a spreadsheet or other software of your choice.

An output table from event-hashes, copied into external spreadsheet software.

Testing

Use this permalink for testing. The output should be:

Event Keccak-256 Hash
Simple(address,address,uint256) 0x0c4aa1b50b54ea9174bfce3c438012e4f2bbf93a058dc8d74185ab16d82ba900
Simple(uint256[],int256,uint8[]) 0x2026044affa2e544dcb961375aedefd2b307e1b946edac0491c979b356280220
Spaces(address,address,uint256) 0xda28d9a3b64acdf2ca6024d6f102d1771bd9d91df417723b1f14c4ae0856c6d3
MultiLine(address,address,uint256) 0x760dd7228125a3ef675a431bf253d71f0e2b83af9ec42e0cfd9d2fae9752fb49
MultiLineSameName(address,address) 0xe18b9597b1182141cedf8b007cb04e23cf5a02d16c74ce2c704fb5dfd7516343
MultiLineSameName(uint256,int256) 0x06b14b8df51d75cfe7ac7998ad1c26ef4c27486f5002d2467e2153e5223afb65

event-hashes's People

Contributors

ardislu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.