---
# System prepended metadata

title: Parachain on kusama-local Workshop

---

Clone from Parachain Workshop - presented by Hang Yin - Phala team.


# Parachain on kusama-local Workshop

1. Get the modified Kusama

    ```bash
    git clone git@github.com:Phala-Network/polkadot.git
    ```

2. Compile

    ```bash
    cd polkadot
    git checkout kusama-para-test-093
    cargo build --release
    ```
    
3. Run 4-node Kusama local (we need 4 nodes to support one parachain)

    ```bash
    # Alice
    ./target/release/polkadot --chain kusama-local -d chains/a --alice --port 31333 --ws-port 19944 --rpc-cors all --node-key 0000000000000000000000000000000000000000000000000000000000000001
    # Bob
    ./target/release/polkadot --chain kusama-local -d chains/b --bob --port 32333 --ws-port 29944 --bootnodes /ip4/127.0.0.1/tcp/31333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
    # Charlie
    ./target/release/polkadot --chain kusama-local -d chains/c --charlie --port 33333 --ws-port 39944 --bootnodes /ip4/127.0.0.1/tcp/31333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
    # Dave
    ./target/release/polkadot --chain kusama-local -d chains/d --dave --port 34333 --ws-port 49944 --bootnodes /ip4/127.0.0.1/tcp/31333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
    ```

4. Prepare your blockchain ([Khala](https://github.com/Phala-Network/khala-parachain))

    ```bash
    cargo build --release
    ```
    
5. Register a parachain id on kusama-local

    - Connect polkadotjs to the full node. In our example, we use `ws-port=19944`
    - SSH port forwarding by: `ssh -L 19944:127.0.0.1:19944 your-server`
    - Note the parachain id got from this step (by default: 2000)
    
5. Get wasm and genesis state

    ```bash
    ./target/release/khala-node export-genesis-wasm -r --chain khala-local-2000 > ./tmp/kernels/staging-genesis.wasm
    ./target/release/khala-node export-genesis-state --chain khala-staging-2000 > ./tmp/kernels/staging-state.hex
    ```
    
6. Register parathread

    ![](https://i.imgur.com/zkZRLPs.png)

7. Upgrade to parachain
    
    - sudo(parasSudoWrapper.sudoScheduleParathreadUpgrade(2000))

    ![](https://i.imgur.com/fkfOypD.png)
    
    - Tip: accelerate by `sudo(paras.forceQueueAction(para))`

8. Export `kusama-local` chain spec for collators

    ```bash
    # In polkadot git repo:
    ./target/release/polkadot build-spec --raw --chain kusama-local > kusama-local.json
    # saved location: /home/h4x/tmp/polkadot/polkadot/kusama-local.json
    ```

8. Start collators

    ```bash
    # Collator 1
    ./scripts/collator.sh \
        -d tmp/chains/a \
        --port 35333 --ws-port 59941 --rpc-cors all \
        --node-key 0000000000000000000000000000000000000000000000000000000000000002

    # Collator 2
    ./scripts/collator.sh \
        -d tmp/chains/b \
        --port 36333 --ws-port 59942 --rpc-cors all \
        --bootnodes /ip4/127.0.0.1/tcp/35333/p2p/12D3KooWHdiAxVd8uMQR1hGWXccidmfCwLqcMpGwR6QcTP6QRMuD

    # Collator 3
    ./scripts/collator.sh \
        -d tmp/chains/c \
        --port 37333 --ws-port 59943 --rpc-cors all \
        --bootnodes /ip4/127.0.0.1/tcp/35333/p2p/12D3KooWHdiAxVd8uMQR1hGWXccidmfCwLqcMpGwR6QcTP6QRMuD
    ```
    
    where `collator.sh` is:
    
    ```bash
    ./target/release/khala-node \
        --chain khala-local-2000 \
        --collator \
        --pruning archive \
        --execution wasm \
        --wasm-execution Compiled \
        "$@" \
        -- \
        --execution wasm \
        --wasm-execution Compiled \
        --chain /home/h4x/tmp/polkadot/polkadot/kusama-local.json \
        --bootnodes /ip4/127.0.0.1/tcp/31333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
    ```
    
    Don't forget to inject session key if you don't use the predefined roles


## Fork-off-relaychain

<https://github.com/Phala-Network/fork-off-relaychain>

1. Fork kusama

    ```bash
    ./fork.sh
    ```

3. Run kusama-local

    ```bash
    ./node.sh --alice # you need 4 validators
    ```

4. Downgrade Statemine
5. Upgrade Parachain


