npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vanity-function-selector

v0.0.1

Published

CLI tool to help you find a suffix for your solidity functon name in order to affect its 4 bytes selector.

Downloads

4

Readme

vanity-function-selector

Introduction

This is a CLI tool to help you find a suffix to your solidity function names in order to affect its 4 bytes selector.

How to use

There are 2 main ways to use this script:

Match pattern

You can run the script to get a function signature to match a given pattern (starting with 0x and followed by 0 to 8 hexadecimal characters). For example you want your mint(address,uint256) to have a signature starting with 0xf00 you can run the following command

$ npx vanity-function-selector 0xf00 mint address uint256

which would output

[WARN] Argument types are not checked for validity. I hope you know what you are doing
Computing... Looking for a suffix for function mint(address,uint256) to get a signature starting with 0xf00
Found suffix: "Cz" after 2493 attempts
0xf001aed5 : mintCz(address,uint256)

so you can rename your function to mintCz and it will have the desired signature (or selector) 0xf001aed5.

Protip: you may want to pass mint_ as an input if you want it to look prettier

[WARN] Argument types are not checked for validity. I hope you know what you are doing
Computing... Looking for a suffix for function mint_(address,uint256) to get a signature starting with 0xf00
Found suffix: "0Ew" after 6585 attempts
0xf00fe9d9 : mint_0Ew(address,uint256)

Zero-bytes

If the first argument you pass is not prefixed with 0x and is a number instead, it will be interpreted as the byte difficulty. Meaning it will try to find a function selector that starts with as many zero-bytes. For example the command

$ npx vanity-function-selector 1 withdraw uint256

will look for a function signature starting with 0x00 (one zero-byte)

Notes

I came accross this need and was unable to find a tool to do it, which I still can't believe. There has to be something that I just didn't find. So anyway, I decided to write my own and then I thought I'd share it. The code is ugly, It's super not-optimized (runs on a single thread) and some decisions in the way it is used are quite opinionated.

By publishing this project, I express my will to make this something that is useful for other people (otherwise, I would have just backed it up somewhere private, right?). So please make suggestions, post issues, send PRs.

The next thing I would love to implement here is to use workers to parallelize the search and make it N-times faster, where N is the number of CPU cores.

Then maybe use proper CLI utilities to parse the arguments, ane maybe switch to -- prefixed arguments and an option object in the main function.

Anyway, I hope this is will be useful for someone