scope 🔭
Scope is a VSCode extension for testing and interacting with smart contracts on the Ethereum blockchain. It is currently in early alpha and under active development. It is built on top of Foundry, ethers-rs and egui; heavy inspiration is drawn from the Remix project.
In many ways, Scope aims to be a GUI wrapper for Foundry. It is intended to be used by developers and security researchers who are already familiar with the command-line tools and want a more visual way to interact with their contracts/tests. Some currently supported features include:
- Deploying contracts against a local Anvil node (or a mainnet fork via
anvil -f <url>
) - Loading existing contracts at an address
- Interacting with contracts either via ABI or raw calldata
- Easy copying of ABI, AST, calldata, return values, etc.
- Setting storage slots and balances
- One-button printing storage layout and contract interfaces via
cast
- Debugging transaction traces via
cast call --trace
+ forge debugger - Running foundry tests
- Misc. CLI wrappers:
- forge build
- slither
- pyrometer
- chisel
(see TODO.md for a scratchpad of planned features)
Installation + setup can be a little finnicky currently but I'm aiming to streamline it.
- Install the extension from the VSCode Marketplace
- Ensure you have foundry installed and run
foundryup
- Start a local Anvil instance via the
anvil
command (take care to not use the terminal window titled "scope"; the extension will use this terminal window for miscellaneous commands). I'd recommend doing this in an external terminal (in case you have to reload VSCode)- You can also use
anvil -f <url>
to fork mainnet state.
- You can also use
- NOTE1 - Scope requires VSCode to be opened in the root directory of a foundry project. It piggybacks on the foundry compiler / command line commands
- NOTE2 - The extension requires an Anvil node to be running at
localhost:8545
BEFORE the extension is activated (it performs some node setup on load -hardhat_autoImpersonateAccount
andhardhat_setBalance
). If you start the node after opening VSCode, you will need to reload the extension (Command + Shift + P
-> "Developer: Reload Webviews")
-
Create a new foundry project via
foundry init scope-test
(or open VSCode at the root of an existing one) -
Navigate to the root directory of the new project and open VSCode with
code .
-
Open
src/Counter.sol
andtest/Counter.t.sol
in the VSCode editor window -
Click the telescope icon to open the extension
-
Press
Compile
to compile the contracts (this will runforge build
in the background; Scope looks for compiled artifacts inout/
)- Alternately, run "forge build" in the terminal and press the "Refresh" button at the top of the extension
-
Select
Counter.sol
-
Click
Deploy
to deploy the contract to the local Anvil node -
(Separate) Select
Counter.t.sol
and run some tests (check the options as well)
Most issues can be resolved with some combination of the following:
- Ensure you have an anvil node running at
localhost:8545
(the default) - Ensure you have VSCode opened at the root of a foundry project
- Reload VSCode or the extension webview -
Command + Shift + P
-> "Developer: Reload Window/Webviews" - Run
forge clean && forge build
in the terminal -> press the "🔄" button at the top of the extension after successful compilation to refresh the contract list (theCompile
button can be error-prone)
- Clone the repo
- Ensure you have foundry installed and run
foundryup
- Start an anvil node (using ethers-rs default):
anvil -m "stuff inherit faith park genre spread huge knee ecology private marble supreme"
- Open VSCode with
scope-js
as the root directory and pressFn + F5
. - Open
./example
as the root directory of the newly-openedExtension Development Host
- The extension should be installed, but may need to be pinned in order to remain visible
- Open
./example/src/Sample.sol
in VSCode- Press "Compile"
- You may need to press the
🔄
button; handling active opening+closing of files is WIP
- Deploy, etc!
- scope-js - VSCode extension logic
- Takes a rust wasm binary and serves it in a VSCode Webview View
- Handles:
- Extension config
- Loading the extension into VSCode
- File system access
- Packaging whole extension to VSIX binary (via @vscode/vsce) for easy installation
- scope-rs - Rust egui application
- Handles:
- Rendering the immediate mode UI (egui claims ~60hz but I'm not sure)
- Application logic
- Compiling to wasm (
scope-rs/build.sh
)
- Handles:
- To compile rust to wasm, run
./build.sh
from within the scope-rs directory- This also copies the wasm + bindings to
scope-js/wbg_out
, which is where the extension knows to look
- This also copies the wasm + bindings to
- To run the extension in dev mode, open vscode (or a VSCode fork) with
scope-js
as the root directory and pressFn + F5
- To add the extension to your live VSCode, package it using @vscode/vsce (
$ vsce package
) and install the extension from VSIX