# Install and build

This page covers the one-time setup to get a fully working TONado Cash development environment.

## Prerequisites

| Tool                                             | Min version | Why                                                            |
| ------------------------------------------------ | ----------- | -------------------------------------------------------------- |
| Node.js                                          | ≥ 20        | Workspaces, native fetch, ESM. v22 recommended.                |
| pnpm                                             | 10.x        | Monorepo package manager.                                      |
| Docker + Docker Compose                          | latest      | Postgres + Redis for the relayer.                              |
| [Acton](https://github.com/ton-blockchain/acton) | 1.0+        | Tolk compiler, sandbox, deploy.                                |
| [circom](https://github.com/iden3/circom)        | 2.1+        | Circuit compilation.                                           |
| [snarkjs](https://github.com/iden3/snarkjs)      | 0.7+        | Groth16 setup + proving. Installed transitively.               |
| TON wallet w/ test TON                           | n/a         | Sender for deposits / relayer wallet for gas.                  |
| Toncenter API key                                | n/a         | RPC access. Get one at [toncenter.com](https://toncenter.com). |

### Installing Acton

```bash
# macOS / Linux. See https://github.com/ton-blockchain/acton for current docs.
curl -fsSL https://acton.org/install.sh | sh
acton --version
```

### Installing circom

```bash
git clone https://github.com/iden3/circom
cd circom && cargo install --path circom
```

## Cloning and installing the workspace

```bash
git clone https://github.com/tonadocash/monorepo
cd tonado-cash
pnpm install

# Typecheck everything as a sanity baseline.
pnpm typecheck

# Build all TS packages and apps.
pnpm build
```

After this you have a working `@tonado/core` SDK, a `tonado` CLI build, and the relayer. You do **not** yet have compiled circuits or contracts.

## Configuring environment

```bash
cp .env.example .env
$EDITOR .env
```

The minimum values for testnet development:

```ini
TON_NETWORK=testnet
TONCENTER_ENDPOINT=https://testnet.toncenter.com/api/v2/jsonRPC
TONCENTER_API_KEY=<get from toncenter.com>

# Wallet that will deploy the contracts. Fund with ≥5 testnet TON.
DEPLOYER_MNEMONIC="word1 word2 ... word24"

# Wallet that will run the relayer. Fund with ≥5 testnet TON.
RELAYER_WALLET_MNEMONIC="word1 word2 ... word24"
RELAYER_WALLET_VERSION=v4R2
```

### Testnet faucets

* [@testgiver\_ton\_bot](https://t.me/testgiver_ton_bot): official, \~5 TON per request.
* [@tonapibot](https://t.me/tonapibot): set to "testnet" mode.
* [@thetonfaucet\_bot](https://t.me/thetonfaucet_bot): community-run backup.

Cross-check balances on [testnet.tonviewer.com](https://testnet.tonviewer.com).

## Building circuits and contracts

```bash
# 1. Download phase-1 BLS12-381 powers-of-tau (one-time, ~50MB).
pnpm circuits:ptau-setup

# 2. Compile withdraw.circom → r1cs + wasm.
#    Runs snarkjs groth16 setup with a DEV contribution. Testnet only.
#    Mainnet must use the multi-party ceremony in deploy/ceremony/.
pnpm circuits:compile

# 3. Generate the Tolk verifier contracts + TS wrappers from the final zkeys.
pnpm verifier:export

# 4. Precompute the merkle-tree zeros table.
pnpm --filter @tonado/contracts run precompute-zeros

# 5. Build the Tolk contracts.
cd apps/contracts && acton build && cd ../..
```

After all five steps:

* `packages/core/artifacts/` contains `withdraw.wasm`, `withdraw_final.zkey`, and `verification_key.json`.
* `apps/contracts/contracts/verifier.tolk` and `verifier_merkle_update.tolk` are real generated verifiers (not placeholders).
* `apps/contracts/contracts/merkle_tree.tolk` has its `zeros[]` table filled.
* `apps/contracts/build/PoolNative.json` and `build/PoolJetton.json` exist with compiled BoCs.

## Verifying Poseidon parity

Three Poseidon implementations must produce identical outputs on every input:

1. The prover: `@tonado/core` `buildPoseidon`.
2. The circuit: `circuits/commitmentHasher.circom` (compiled `--prime bls12381`).
3. The on-chain Tolk Poseidon: `apps/contracts/contracts/poseidon.tolk`.

CI runs [`apps/contracts/scripts/check-poseidon-parity.ts`](https://github.com/tonadocash/monorepo/blob/main/apps/contracts/scripts/check-poseidon-parity.ts) on every PR to catch drift between the artifacts. Run it locally:

```bash
tsx apps/contracts/scripts/check-poseidon-parity.ts
```

If parity fails, deposits will produce commitments that the circuit doesn't accept, and proofs will silently mis-verify. **Do not skip this check.**

## Running the test suite

```bash
# Sandbox tests for Tolk contracts (~131 tests across deposit, withdraw, admin, capacity, gas).
pnpm --filter @tonado/contracts test

# Circuit end-to-end smoke (after `pnpm circuits:compile`).
tsx apps/contracts/tests/circuit.spec.ts

# Off-chain unit tests for @tonado/core.
pnpm --filter @tonado/core test
```

All three must be green before any deployment.

## Linting and formatting

```bash
pnpm lint
pnpm lint:fix
pnpm format        # prettier for TS
pnpm format:tolk   # acton fmt for .tolk files
```

`pnpm format:tolk:check` is the dry-run variant used in CI.

## Next

* Deploy a pool: [Deploying pools](/for-developers/deploying-pools.md).
* Use the CLI: [CLI reference](/for-developers/cli-reference.md).
* Use the SDK programmatically: [Core SDK](/for-developers/sdk-core.md).
* Run the relayer: [Running a relayer](/for-developers/running-a-relayer.md).


---

# 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.tonadocash.com/for-developers/install-and-build.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.
