This script allows bootstrapping a new substrate chain with the current state of a live chain. Using this, you can create a fork of Polkadot, Kusama and other substrate chain for development purposes.
-
Clone this repository and install dependencies
git clone https://github.com/maxsam4/fork-off-substrate.git cd fork-off-substrate npm i
-
Create a folder called
data
inside the top folder (fork-off-substrate
).mkdir data
-
Copy the executable/binary of your substrate based node inside the data folder and rename it to
binary
. -
Copy the runtime WASM blob of your substrate based blockchain to the data folder and rename it to
runtime.wasm
. To get the WASM blob, compile your blockchain and look for./target/release/wbuild/runtime/runtime.compact.wasm
. If you are forking Polkadot/Kusama/Westend, you can download the WASM blobs from Polkadot's release page. -
If your substrate chain uses additional custom types than what are available in polkadot.js, define them in a JSON file of format
{ "types": { <YOUR_TYPES> } }
. Copy the file to thedata
folder and rename it toschema.json
. -
Either run a full node for your blockchain locally(Recommended) or have an external endpoint handy.
-
Run the script
-
If using a local node, simply run the script using
npm start -- --chain <desired_chain>
-
If you are using an external/non-default endpoint, you need to provide it to the script via the
HTTP_RPC_ENDPOINT
environment variableHTTP_RPC_ENDPOINT=https://example.com npm start -- --chain <desired_chain>
-
You can also specify a desired block to scrape data from using
--block <block_hash>
. It may be necessary to pull this from an archive node if the block is old.
-
-
You should have the genesis file for the forked chain inside the
data
folder. It will be calledfork.json
. -
You can now run a new chain using this genesis file
NOTE: most necessary tweaks are handled by the script, but for Moonbeam or Moonriver it will be necessary to manually replace an existing collator with alices' address (
0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac
)../binary --chain fork.json --alice --sealing 1000
If you would like to understand how this script works, please read this blog post
This script is based on a script shared in the substrate riot channel