Skip to content

Commit 1937df0

Browse files
authored
feat(guides): add steps (#1610)
1 parent 61576a8 commit 1937df0

File tree

6 files changed

+84
-24
lines changed

6 files changed

+84
-24
lines changed

vocs/docs/pages/guides/deterministic-deployments-using-create2.md

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ With `CREATE2`, you can use the same deployer account to deploy contracts to the
1414

1515
For the best user experience it is recommended to avoid having different addresses of the same deployment across different EVM chains.
1616

17-
## Getting started
17+
:::note
18+
This guide is intended to help you get started with configuring deterministic deployments using `CREATE2`.
19+
By default, `new Counter{salt: salt}()` will use the deterministic deployer at [`0x4e59b44847b379578588920ca78fbf26c0b4956c`](https://github.com/Arachnid/deterministic-deployment-proxy). Note that the deployer may not be available on all EVM chains.
20+
A different deployer address can be configured by setting `create2_deployer` in `foundry.toml` or by using `--create2-deployer` argument.
1821

19-
> ℹ️ **Note**
20-
>
21-
> This guide is intended to help you get started with configuring deterministic deployments using `CREATE2`.
22-
> By default, `new Counter{salt: salt}()` will use the deterministic deployer at [`0x4e59b44847b379578588920ca78fbf26c0b4956c`](https://github.com/Arachnid/deterministic-deployment-proxy). Note that the deployer may not be available on all EVM chains.
23-
> A different deployer address can be configured by setting `create2_deployer` in `foundry.toml` or by using `--create2-deployer` argument.
22+
:::
2423

25-
## Configuring your `foundry.toml`
24+
Follow these steps to set up deterministic deployments:
25+
26+
::::steps
27+
28+
### Configure your `foundry.toml`
2629

2730
In order to reliably deploy to deterministic addresses we will need to make sure our bytecode stays the same. To do so configure our `foundry.toml` as follows:
2831

@@ -34,15 +37,23 @@ bytecode_hash = "none"
3437
cbor_metadata = false
3538
```
3639

37-
### Solc version
40+
### Pin your Solc version
3841

3942
It is required to pin your `solc` (Solidity) version. It is generally recommended to use a recent version or, if preferred, the latest version.
4043

41-
### EVM version
44+
```toml
45+
solc = "<SOLC_VERSION>"
46+
```
47+
48+
### Set your EVM version
4249

4350
Next, configure your `evm_version`. It is generally recommended to use the most recent hardfork but depending on your deployment targets this may need to use an older hardfork due to opcode incompatibilities.
4451

45-
### Metadata and bytecode
52+
```toml
53+
evm_version = "<EVM_VERSION>"
54+
```
55+
56+
### Configure metadata and bytecode settings
4657

4758
By default the Solidity compiler appends the hash of the metadata file at end of the bytecode. This bytecode includes things like the compiler version and the ABI.
4859

@@ -141,11 +152,11 @@ cbor_metadata = false
141152

142153
You are not including the metadata hash as part of the bytecode. This means that whilst your bytecode can now be deterministic you won't be able to have a [`full match`](https://docs.sourcify.dev/docs/full-vs-partial-match/#full-perfect-matches), only a [`partial match`](https://docs.sourcify.dev/docs/full-vs-partial-match/#partial-matches) when verifying your contracts. Depending on your requirements this may be acceptable.
143154

144-
### Optimizer
155+
### Configure the optimizer
145156

146157
If you are enabling the `optimizer` make sure your `optimizer_runs` stay consistent.
147158

148-
### Create2 factory
159+
### Set up the CREATE2 factory
149160

150161
By default, your contracts won't use the default (or specified using the `create2_deployer` configuration) create2 factory and will default to executing the create2 opcode from the contract it's executed on. For example, this behavior occurs when running tests or executing scripts without a private key.
151162

@@ -157,6 +168,8 @@ always_use_create_2_factory = true
157168

158169
If you wish to always use the create2 factory. This comes handy if you wish to use the create2 factory deployment addresses in your tests for example.
159170

171+
::::
172+
160173
## Deploying the contract
161174

162175
When using Solidity's default `CREATE` where the new address of a contract is determined by taking the `hash` of the `sender`'s address and the `sender`'s `nonce`:

vocs/docs/pages/guides/eip712.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Uniswap's `Permit2` system utilizes the `PermitHash.sol` library to create hashe
5050

5151
Our objective is to focus on a few hashing functions within `PermitHash.sol`. We will provide these functions with sample data and then use `vm.eip712HashStruct` —with the same data and the canonical EIP-712 type definition— to determine if the generated hashes match.
5252

53-
#### Setting up the test environment
53+
### Setting up the test environment
5454

5555
Before starting with the validations, we have to create the `PermitHash.t.sol` test file.
5656

vocs/docs/pages/guides/forking-mainnet-with-cast-anvil.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ description: Fork live Ethereum networks using Anvil and interact with real cont
66

77
By combining [Anvil][anvil] and [Cast][cast], you can fork and test by interacting with contracts on a real network. The goal of this guide is to show you how to transfer DAI tokens from someone who holds DAI to an account created by Anvil.
88

9-
## Getting started
9+
Follow these steps to fork mainnet and transfer DAI tokens:
10+
11+
::::steps
12+
13+
### Fork mainnet with Anvil
1014

1115
Let's start by forking mainnet.
1216

@@ -16,7 +20,7 @@ anvil --fork-url https://mainnet.infura.io/v3/$INFURA_KEY
1620

1721
You will see 10 accounts are created with their public and private keys. We will work with `0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266` (Let's call this user Alice).
1822

19-
## Transferring DAI
23+
### Set up environment variables
2024

2125
Go to Etherscan and search for holders of DAI tokens ([here](https://etherscan.io/token/0x6b175474e89094c44da98b954eedeac495271d0f#balances)). Let's pick a random account. In this example we will be using `0xfc2eE3bD619B7cfb2dE2C797b96DeeCbD7F68e46`. Let's export our contracts and accounts as environment variables:
2226

@@ -26,6 +30,8 @@ export DAI=0x6b175474e89094c44da98b954eedeac495271d0f
2630
export UNLUCKY_USER=0xfc2eE3bD619B7cfb2dE2C797b96DeeCbD7F68e46
2731
```
2832

33+
### Check initial balances
34+
2935
We can check Alice's balance using [`cast call`][cast-call]:
3036

3137
```sh
@@ -44,6 +50,8 @@ cast call $DAI \
4450
21840114973524208109322438
4551
```
4652

53+
### Transfer DAI tokens
54+
4755
Let's transfer some tokens from the unlucky user to Alice using [`cast send`][cast-send]:
4856

4957
```sh
@@ -60,6 +68,8 @@ blockNumber 15052891
6068
...
6169
```
6270

71+
### Verify the transfer
72+
6373
Let's check that the transfer worked:
6474

6575
```sh
@@ -74,6 +84,8 @@ cast call $DAI \
7484
21540114973524208109322438
7585
```
7686

87+
::::
88+
7789
[anvil]: ../reference/anvil/
7890
[cast]: ../cast/reference/
7991
[cast-call]: ../cast/reference/cast-call.md

vocs/docs/pages/guides/project-setup/clone-a-verified-contract.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ description: Clone verified on-chain contracts as Foundry projects with source c
44

55
## Clone a Verified Contract
66

7+
::::steps
8+
9+
### Clone the contract
10+
711
To clone an on-chain verified contract as a Forge project, use [`forge clone`](/forge/reference/forge-clone), say [WETH9](https://etherscan.io/address/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2) on Ethereum mainnet:
812

913
```sh
@@ -12,16 +16,24 @@ To clone an on-chain verified contract as a Forge project, use [`forge clone`](/
1216

1317
This creates a new directory `WETH9`, configures it as a foundry project and clones all the source code of the contract into it. This also initializes a new `git` repository.
1418

19+
### Review the cloned project
20+
21+
After cloning, you'll see the following output:
22+
1523
```sh
1624
// [!include ~/snippets/clone_contract/forge-clone:output]
1725
```
1826

1927
The cloned Forge project comes with an additional `.clone.meta` metadata file besides those ordinary files that a normal Forge project has.
2028

29+
### Examine the metadata
30+
2131
Let's see what the `.clone.meta` file looks like:
2232

2333
```sh
2434
// [!include ~/snippets/clone_contract/clone-meta:output]
2535
```
2636

2737
`clone.meta` is a compact JSON data file that contains the information of the on-chain contract instance, e.g., contract address, constructor arguments, etc. More details of the metadata can be found in the [reference](/forge/reference/forge-clone).
38+
39+
::::

vocs/docs/pages/guides/project-setup/creating-a-new-project.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ description: Initialize a new Foundry project using forge init with default temp
44

55
## Creating a New Project
66

7+
::::steps
8+
9+
#### Initialize the project
10+
711
To start a new project with Foundry, use [`forge init`](/forge/reference/forge-init):
812

913
```sh
@@ -12,31 +16,42 @@ To start a new project with Foundry, use [`forge init`](/forge/reference/forge-i
1216

1317
This creates a new directory `hello_foundry` from the default template. This also initializes a new `git` repository.
1418

19+
:::info
1520
If you want to create a new project using a different template, you would pass the `--template` flag, like so:
16-
1721
```sh
1822
forge init --template https://github.com/foundry-rs/forge-template hello_template
1923
```
24+
:::
2025

21-
For now, let's check what the default template looks like:
26+
#### Navigate to the project directory
27+
28+
Move into your newly created project:
2229

2330
```sh
2431
cd hello_foundry
2532
```
2633

34+
#### Explore the project structure
35+
36+
Let's check what the default template looks like:
37+
2738
```sh
2839
// [!include ~/snippets/output/hello_foundry/tree:all]
2940
```
3041

3142
The default template comes with one dependency installed: Forge Standard Library. This is the preferred testing library used for Foundry projects. Additionally, the template also comes with an empty starter contract and a simple test.
3243

33-
Let's build the project:
44+
#### Build the project
45+
46+
Compile your contracts:
3447

3548
```sh
3649
// [!include ~/snippets/output/hello_foundry/forge-build:all]
3750
```
3851

39-
And run the tests:
52+
#### Run the tests
53+
54+
Execute the test suite:
4055

4156
```sh
4257
// [!include ~/snippets/output/hello_foundry/forge-test:all]
@@ -45,3 +60,5 @@ And run the tests:
4560
You'll notice that two new directories have popped up: `out` and `cache`.
4661

4762
The `out` directory contains your contract artifact, such as the ABI, while the `cache` is used by `forge` to only recompile what is necessary.
63+
64+
::::

vocs/docs/pages/guides/scripting-with-solidity.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Solidity scripting is a way to declaratively deploy contracts using Solidity, in
88

99
Solidity scripts are like the scripts you write when working with tools like Hardhat; what makes Solidity scripting different is that they are written in Solidity instead of JavaScript, and they are run on the fast Foundry EVM backend, which provides advanced simulation with dry-run capabilities.
1010

11-
## Overview
11+
## How `forge script` works?
1212

1313
`forge script` does not work in an asynchronous manner. First, it collects all transactions from the script, and only then does it broadcast them all. It can essentially be split into 4 phases:
1414

@@ -23,21 +23,25 @@ Transactions that previously failed or timed-out can be submitted again by provi
2323

2424
Given this flow, it's important to be aware that transactions whose behaviour can be influenced by external state/actors might have a different result than what was simulated on step `2`, e.g. front running.
2525

26-
## Getting started
26+
## Setup `Counter` Project
2727

2828
Let's try to deploy the basic `Counter` contract Foundry provides:
2929

3030
```sh
3131
forge init Counter
3232
```
3333

34-
Next let's try compiling our contracts to make sure everything is in order.
34+
Next compile our contracts to make sure everything is in order.
3535

3636
```sh
3737
forge build
3838
```
3939

40-
## Deploying our contract
40+
## Deploying the `Counter` contract
41+
42+
::::steps
43+
44+
### Get RPC and Etherscan API Keys
4145

4246
We are going to deploy the `Counter` contract to the Sepolia testnet but in order to do so we will need to complete a few prerequisites:
4347

@@ -70,7 +74,7 @@ Some faucets require you to have a balance on Ethereum mainnet.
7074

7175
If so, claim the testnet ETH on a wallet you control and transfer the testnet ETH to your newly created deployer keypair.
7276

73-
4. Get a Sepolia Etherscan API key.
77+
4. Get a Sepolia Etherscan API key [here](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics).
7478

7579
### Configuring `foundry.toml`
7680

@@ -352,3 +356,5 @@ Transactions saved to: /home/user/counter/broadcast/Counter.s.sol/31337/run-late
352356
353357
Sensitive values saved to: /home/user/counter/cache/Counter.s.sol/31337/run-latest.json
354358
```
359+
360+
::::

0 commit comments

Comments
 (0)