Skip to content

wighawag/template-foundry

Repository files navigation

template-foundry

A template to build, deploy and test smart contracts using foundry-rs/forge and forge-deploy

This template uses npm to make it easy to integrate in a full stack monorepo.

Open in Gitpod

How to use?

We are assuming here that you already setup your env as specified in the initial setup section

Compile your contracts

pnpm compile

Test your contracts

pnpm test

See how the Counter.t.sol test use the deploy script to get setup, removing the need to duplicate the deployment procedure.

watch for changes and rebuild automatically

pnpm watch_compile

deploy your contract

  • in memory only:

    pnpm run deploy void
  • on localhost

    This assume you have anvil running : anvil

    pnpm run deploy localhost
  • on a network of your choice

    Just make sure you have RPC_URL or RPC_URL_<network> set for it either in env.local or .env.<network>.local

    pnpm run deploy <network>

export your contracts (abi+address):

pnpm export localhost contracts.json

execute script on the deployed contract

pnpm script localhost script/UpdateCounter.s.sol --sig 'run(uint256)' 42;

zellij

zellij is a useful multiplexer (think tmux) for which we have included a layout file to get started

Once installed simply run

pnpm start

And you'll have anvil running as well as watch process executing tests on changes

if you want to try zellij without install try this :

bash <(curl -L zellij.dev/launch) --layout zellij.kdl

In the shell in the upper pane, you can deploy your contract via

pnpm run deploy

Initial Setup

You need to have these installed

  • nodejs

    For windows (see more info here), you will need to select the option "Automatically install the necessary tools....". Note that process will open a powershell window and will take a while (it does not even show progress).

    This step will allow foundry/forge to work

  • pnpm

    npm i -g pnpm
  • foundry

    curl -L https://foundry.paradigm.xyz | bash;
    export PATH=$HOME/.foundry/bin:$PATH # or load it from your shell config which the script above should have configured
    foundryup

Then you need to install the local dependencies with the following command:

pnpm i

We also recommend to install zellij to have your dev env setup in one go via pnpm start

Windows

Tested from a fresh install of : https://www.microsoft.com/en-US/software-download/windows10ISO on virtualbox.

You first install bash if you do not have already. For that we are using git which comes with bash.

You can install it via scoop.

scoop install git

Or you can use the installer from https://gitforwindows.org/.

If you that last option, you can choose "Use Git and optional Unix tolls from the Command Prompt" and you'll have bash accessible from cmd.exe. otherwise you need to use "Git Bash Here"

Anyway after that you should be able to get into a bash shell.

bash

There you can clone the repo if you did not already and cd into it.

git clone https://github.com/wighawag/template-foundry.git
cd template-foundry

Then you can install the dependencies as stated in the initial setup section

wezterm

on Windows zellij multiplexer is not available

We recommend you install wezterm instead

With that you can do the following to get started:

pnpm start:wezterm

About

A basic template that uses foundry-rs/forge and forge-deploy to deploy and test ethereum smart contracts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published