Skip to content

Commit

Permalink
Configure Hardhat project for running extension on a forked Mainnet
Browse files Browse the repository at this point in the history
In this commit we create a Hardhat project that allows for running Taho
extension on a forked Mainnet. As part of this we're configuring a `hardhat`
network in the Hardhat config file. The fork will begin on a block specified in
the `blockNumber` parameter. The `url` parameter should hold an url to a
JSON-RPC node that's based on your personal Infura/Alchemy API key (e.g.
`https://mainnet.infura.io/v3/<key>`). The suggested value for `chainId` is
`1337`.
The steps to run the network are described in the README file.
Any actions performed on the `hardhat` network will only be applied locally,
they will not affect the real Mainnet network.
  • Loading branch information
michalinacienciala committed Jun 15, 2023
1 parent bd75368 commit cfccbfe
Show file tree
Hide file tree
Showing 8 changed files with 1,486 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ app/extension-scripts/api/playground/
.vscode
playwright-report
test-results/
ci/cache/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist
# Ignore weblate json translation formatting
ui/_locales/**/*.json
!.github
ci/cache
8 changes: 7 additions & 1 deletion .tsconfig-eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
"**/*.tsx",
".github/**/*.js"
],
"exclude": ["node_modules", "dist", "**/validate/*.js", "**/local-chain/**"]
"exclude": [
"node_modules",
"dist",
"**/validate/*.js",
"**/local-chain/**",
"ci/cache"
]
}
37 changes: 37 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Running Taho extension on a forked Mainnet

## Configuration / running

To run the extension on a forked Mainnet:

1. Configure required environment variables (either by setting them in `../.env`
or directly in the console):
`USE_MAINNET_FORK=true` (needed for building the package)
`MAINNET_FORK_CHAIN_ID=1337` (needed for running Hardhat, `1337` is the
suggested and a default value)
`CHAIN_API_URL=<Insert_your_API_URL_here>` (needed for running Hardhat, may
be e.g. Alchemy or Infura API URL)
`FORKING_BLOCK=<Insert_forking_block_here>` (needed for running Hardhat, if
not specified, current block will be used)

2. Run the following commands from root:
`yarn install`
`yarn start` (or `yarn build`)
`cd ci`
`npx hardhat node --network hardhat`

3. Unpack `./dist/chrome` to Chrome Extensions.

## What wallet features work / don't work on the `hardhat` network

When run on `1337`:

:heavy_plus_sign: we can use specific block as a start.
:heavy_plus_sign: we can send txs and do swaps (balances updated)
:heavy_plus_sign: we can browse NFTs
:heavy_minus_sign: the activities are not loading
:heavy_minus_sign: wallet shows strange assets
:heavy_minus_sign: if no cache exists, loading assets takes long, account
avatars may look strange

State of the network is lost after Hardhat reset.
23 changes: 23 additions & 0 deletions ci/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HardhatUserConfig } from "hardhat/config"
import "dotenv-defaults/config"

/* eslint-disable @typescript-eslint/no-var-requires */
require(`dotenv-defaults`).config({
path: "../.env",
defaults: "../.env.defaults",
})

const config: HardhatUserConfig = {
networks: {
hardhat: {
forking: {
enabled: true,
url: process.env.CHAIN_API_URL || "",
blockNumber: parseInt(process.env.FORKING_BLOCK ?? "", 10),
},
chainId: parseInt(process.env.MAINNET_FORK_CHAIN_ID ?? "1337", 10),
},
},
}

export default config
20 changes: 20 additions & 0 deletions ci/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@tallyho/ci",
"version": "0.0.1",
"description": "Taho, the community owned and operated Web3 wallet: window provider is responsible for creating the in-page object for communication.",
"repository": "[email protected]:thesis/tally-extension.git",
"author": "Michalina Cienciala",
"license": "GPL-3.0",
"keywords": [
"ethereum",
"bitcoin",
"cryptocurrency",
"wallet",
"web3",
"dapp"
],
"devDependencies": {
"dotenv-defaults": "^5.0.2",
"hardhat": "^2.14.0"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"background",
"provider-bridge",
"provider-bridge-shared",
"window-provider"
"window-provider",
"ci"
],
"dependencies": {
"@ethersproject/providers": "5.5.3",
Expand Down Expand Up @@ -109,6 +110,7 @@
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^4.2.0",
"fork-ts-checker-webpack-plugin": "^6.3.2",
"hardhat": "^2.14.0",
"install": "^0.13.0",
"jest": "^27.2.2",
"npm": "^7.5.6",
Expand Down
Loading

0 comments on commit cfccbfe

Please sign in to comment.