New pocket knife tool for developers: pocketh ✨

Hello people!

I wanted to share with all of you this simple tool I’m working on: pocketh

It’s a pocket knife cli tool intended to aid developers/auditors when annoying questions come up, such as:

  • “Whats the current block number in mainnet?”
  • “When was block 7200000?”
  • “How many wei is 2 finney?”
  • “What does the inheritance tree of MyContract.sol look like?”
  • “Whats 1982 in hex? =P”

The motivation for the tool came up the other day when I needed (a) a script to scan events in mainnet and (b) scan transactions to a contract on mainnet that hit a particular function. If you google around a bit, you’ll find solutions to any of these problems. But I thought, “Why not start compiling all these scripts into a single tool to rule them all?!”. In fact, these two scripts are now things that pocketh can do via the txs and pastevents commands.

Other things that pocketh can do:

  • Show all members of a contract, including inherited contracts.
  • List all the function selectors of a contract.
  • Display calldata in a readable format.
  • Disassemble bytecode to opcodes.
  • Query the blockchain on a particular block or transaction.
  • Provide info about a network such as latest block, etc.
  • Convert hex<>string.
  • Pad hexadecimals.
  • Compile!

If you can think of something useful that could be added to the tool, pls don’t hesitate to create a new issue in the repo with your feature request. Keep in mind that the tool is intended to only read the blockchain for simplicity, i.e. it is not intended to send txs.

Even better, if you want to throw a PR, you’re more than welcome! Architecture-wise, each command/script should be self contained, so there is no complex architecture going on. It’s basically a collection of scripts.

Enjoy!

5 Likes

I just added a compile command to pocketh which is pretty useful if you want to compile something on the go. Usually, compiling with native solc is quite cumbersome because you always have a fixed solc version installed in your system (e.g. 0.5.8), and your source may use an incompatible version (e.g. pragma solidity ^0.4.24;). Also, with solc, you’d need to use the standard json input/output to actually obtain the JSON file you want, which is a major bummer. An alternative is to use truffle, which has the ability to download solcjs versions, but still you have to setup the truffle project around your contract, edit truffle-config.js for the compiler version you want, etc… BORING :rolleyes:
With pocketh you can just do:
pocketh compile KittyCore.sol tmp/build/
And it will automatically detect the solcjs compiler it needs from the source’s pragma directive, download the compatible solcjs version, cache it for later use and voila! It should be able to resolve imports and output truffle-compatible JSON files. (edited)

3 Likes

Hello Alejandro,

I see one interesting thing here that I was working on a while ago (If I correctly understood the meaning)

  • Show all members of a contract, including inherited contracts.

So, this is actually very cool, and if I get it correct, is the same as what I did with solviz, to be able to get all inheritance and method calls.

Is there a way where we can merge efforts?
Thank you.

3 Likes

Sure! Why dont we have a quick chat about it? Reach me at palebluedot@gmail.com

3 Likes