# Local Deployment Guide

Below is a practical guide on how to spin up your own instance and deploy your contract(s) to a local THORChain environment so you can:

* Run a simulated THORChain network locally (Midgard, THORNode, mock L1 chains)
* Interact with the chain via CLI and APIs
* Build and test contracts with no reliance on external node operators

## Setup local environment

If you want to build and run thornode or midgard locally (e.g. for custom tooling or debugging), follow this setup using macOS as an example.

#### 1. Install Required Tools

`brew install golang coreutils binutils diffutils findutils gnu-tar gnu-sed gawk grep make git protobuf`

#### 2. Update Your PATH (GNU Compatibility)

macOS uses BSD tools by default — THORChain requires GNU tools. Add this to your \~/.zshrc:

`# Core GNU tools`\
`export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"`\
`export PATH="/opt/homebrew/opt/binutils/bin:$PATH"`\
`export LDFLAGS="-L/opt/homebrew/opt/binutils/lib"`\
`export CPPFLAGS="-I/opt/homebrew/opt/binutils/include"`\
\
`export PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH"`\
`export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"`\
`export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"`\
`export PATH="/opt/homebrew/opt/gawk/libexec/gnubin:$PATH"`\
`export PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"`\
`export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH"`\
\
`# PostgreSQL for Midgard`\
`export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"`\
`export LDFLAGS="-L/opt/homebrew/opt/postgresql@16/lib"`\
`export CPPFLAGS="-I/opt/homebrew/opt/postgresql@16/include"`\
\
`# Go binaries`\
`export GOBIN=$GOPATH/bin`\
\
`# Reload shell`\
`source ~/.zshrc`

#### 3. Verify Your Tools

`which gawk && gawk --version`\
`which gsed && gsed --version`

These should point to paths under `/opt/homebrew/opt/`.

#### 4. Install Docker

Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)

Make sure it’s running before proceeding.

## Setup Localnet

#### 1. Clone THORNode

`git clone https://gitlab.com/thorchain/thornode.git`\
`cd THORNode`&#x20;

#### 2. Create mocknet

Create deployment on mocknet to spin up a full local, permissioned network to check that all contracts have the permissions they need&#x20;

`make run-mocknet`&#x20;

#### 3. Start mocknet and set permissions

Start the local mocknet and set wasm permission

`make start-mocknet`&#x20;

The command spins up: 4 validator nodes, Midgard, L1 mocks (BNB, BTC, ETH)

You’ll need to have a local version with wasm\_permissions\_mocknet containing your permissions. Set WASMPERMISSIONLESS mimir to 1 to be able to store contracts on the thornode container:&#x20;

`echo password | thornode tx thorchain mimir --keyring-backend file --from thorchain --chain-id thorchain --yes WASMPERMISSIONLESS 1`&#x20;

#### 4. Access Services

<table data-header-hidden><thead><tr><th width="241.91015625"></th><th></th></tr></thead><tbody><tr><td>Service</td><td>URL</td></tr><tr><td>Midgard API</td><td>http://localhost:8080/v2</td></tr><tr><td>THORNode RPC</td><td>http://localhost:1317</td></tr><tr><td>ETH RPC (mock)</td><td>http://localhost:8545</td></tr><tr><td>BNB RPC</td><td>http://localhost:26650</td></tr></tbody></table>

#### Helpful Localnet Commands

| Task                    | Command                         |
| ----------------------- | ------------------------------- |
| Stop the environment    | make stop                       |
| Rebuild and start clean | make clean start                |
| Tail logs               | docker compose logs -f          |
| Restart Midgard only    | docker compose restart midgard  |
| Interact with THORNode  | Use thornode CLI or curl to API |

#### Example Interactions

Query Midgard:

`curl http://localhost:8080/v2/pools`

Query THORNode RPC:

`curl http://localhost:1317/thorchain/inbound_addresses`<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rujira.network/developers/local-deployment-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
