Foundry - chisel

Stefan Alfbo - Dec 26 '23 - - Dev Community

The Chisel component in the Foundry toolkit is a very sophisticated REPL tool designed for Solidity. This tool is incredibly useful for rapidly evaluating Solidity code snippets in a local or forked network environment.

As an integral component of the Foundry suite, Chisel is installed along with other tools like forge, cast, and anvil. So make sure you got foundry installed.



# Install it
curl -L https://foundry.paradigm.xyz | bash
# or update
foundryup


Enter fullscreen mode Exit fullscreen mode

When foundry is installed locally we can just fire up a terminal and type chisel to get started.

chisel start

As you can see, type !help to show available commands. To quit the REPL you will have use the command !quit. The common theme is the use of ! as prefix for all commands.

Lets start the test drive with chisel by playing with some expressions.

Simple expression

We can see that if we do the expression 1337 + 42 in Solidity we will get the result 1379 of the type uint and in hex it will be 0x0000000000000000000000000000000000000000000000000000000000000563 (as a 32 byte word or 256 bit).

In the REPL we can tinker with any Solidity code that we might think of. Here is an example of some testing with the Solidity function require.

require

This make it very easy to try something out or if you just want to explore something in Solidity.

It is also possible to save your session so you can go back to it at a later time. The command for that is !s or !save.

Save session

Now you can quit the session, !q, and in the terminal type chisel list to list all your saved sessions in chisel.

Chisel list

By using the load command when starting a chisel session you can load any of the earlier saved sessions. When loaded you can use the session command !source to display the source code of the loaded/current session.

chisel load

Other notable features of chisel is the possibility to fork a network, !fork <rpc-url> and toggling traces, !traces.

traces

We have only scratched the surface of the tool yet, but I hope you will explore it more either via Foundry book or its GitHub page.

Happy REPLing

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .