Skip to content

Commit

Permalink
Add local Sourcify instance documentation
Browse files Browse the repository at this point in the history
Special thanks to spacecake8961 for creating the first draft of these docs!
  • Loading branch information
sealer3 committed Apr 18, 2024
1 parent 45d8133 commit ec4879e
Showing 1 changed file with 96 additions and 1 deletion.
97 changes: 96 additions & 1 deletion docs/sourcify.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Please see our [ipfs integration docs](./ipfs.md) for more info about how we han

Standard HTTP connection to their repo at https://repo.sourcify.dev/

Fast access to fresh verified data. On the other hand it is less private and centralized.
Fast access to fresh verified data. On the other hand, it is centralized and leaks all addresses you visit in Otterscan to the server.

### Local snapshot **(deprecated; soon to be removed)**

Expand Down Expand Up @@ -53,3 +53,98 @@ Rather than using the default `ipfs.io` and `repo.sourcify.dev` sites for access
```

This is useful if you have your own Sourcify repository hosted locally, in which case all of your Otterscan activity will be private.

## Run a local Sourcify instance on your dev network

### Launch a local chain

Launch an Otterscan-compatible local Ethereum RPC node hosting your development server.

- Erigon:
- `./erigon --chain=dev --datadir=dev --http.api eth,erigon,trace,ots,ots2 --http.corsdomain "*" --http.vhosts "*" --mine --fakepow`
- Note: The Erigon devnet only supports a pre-Shanghai (pre-Merge) version of Ethereum. When compiling your contracts, you'll have to set the `evmTarget` to `london` for them to run at all on the devnet.
- You'll have to create a full-fledged Ethereum test network in Erigon if you want to run a modern version of the EVM.
- Foundry's [Anvil](https://book.getfoundry.sh/reference/anvil/):
- `anvil`
- Note: Anvil does not support ots2 RPC methods, so make sure `experimental` is set to `false` in your Otterscan config.

### Sourcify

1. Clone the Sourcify repository:

```shell
git clone https://github.com/ethereum/sourcify.git`
```

2. To add support for your local blockchain, create a JSON file `services/server/src/sourcify-chains.json`:
```json
{
"1337": {
"sourcifyName": "Local chain",
"supported": true,
"rpc": [
"http://localhost:8545"
]
}
}
```

You can adjust the chain ID `1337` and the RPC host `http://localhost:8545` as needed. The default chain ID for the Erigon devnet is 1337, and the default for Anvil is 31337.

3. Adjust the repository URL in `ui/.env.development` since for simplicity we aren't using Sourcify's h5ai-nginx file viewer:

```shell
REACT_APP_REPOSITORY_SERVER_URL=http://localhost:5555/repository
```

4. Build all needed Sourcify components, notably the server and the UI:

```shell
npm run build:clean
```

5. Start the Sourcify server:

```shell
NODE_ENV=development npm run server:start
```

6. Start the Sourcify UI:

```shell
npm run ui:start
```

### Otterscan configuration

To use the local Sourcify instance, you need to point to it in Otterscan's configuration file.
In your Otterscan configuration JSON, specify your local Sourcify repository as the Sourcify source:
```
"sourcifySources": {
"ipfs": "http://localhost:5555/repository",
"central_server": "http://localhost:5555/repository"
}
```
### Verifying contracts
#### Verifying through the Sourcify UI
You can verify contracts using the Sourcify UI by going to http://localhost:3000/#/verifier in your browser.
#### Verifying with Forge
1. If you deploy using a [Forge script](https://book.getfoundry.sh/reference/forge/forge-script), you should add the following contract verification arguments to the command:
```shell
forge script Deploy.s.sol .... --verify --verifier sourcify --verifier-url http://localhost:5555
```
2. If you want to deploy a contract without a script, you can use `forge create` to create the deployment transaction. Create a folder named `contracts` and put your contract files in there.
Here is how you would deploy a smart contract called `MyContract` with constructor arguments `0x67b1d87101671b127f5f8714789C7192f7ad340e` and `123456`:
```shell
./forge create --verify --verifier sourcify --verifier-url http://localhost:5555/ --interactive --optimize --rpc-url http://localhost:8545/ MyContract --constructor-args 0x67b1d87101671b127f5f8714789C7192f7ad340e 123456
```

0 comments on commit ec4879e

Please sign in to comment.