For the complete documentation index, see llms.txt
Deploy the hello world contract
The Hello World tutorial deploys the contract to a Docker-based local devnet with pre-funded wallets. In this guide, you deploy the same example-hello-world contract to Preprod, the public Midnight testnet used for final testing before mainnet. After deployment, the contract is visible on the Preprod block explorer and reachable from any Preprod indexer.
Prerequisites
Before you begin, ensure you have:
- Completed the Hello World tutorial against the local devnet (
yarn test:localpassing). - A clone of
example-hello-worldwith the contract already compiled (contracts/managed/hello-world/populated). - A Midnight-compatible wallet (such as Lace or 1AM) configured for the Preprod network, or an existing 24-word mnemonic / 64-character hex seed you control.
- Docker engine running (the proof server runs as a container).
Generate a wallet
You need a wallet on the Preprod network to sign the deployment and call transactions. The test suite accepts either a 24-word BIP-39 mnemonic or a 64-character hex seed; pick whichever your wallet exports.
Using a Midnight-compatible wallet (such as Lace or 1AM):
- In your wallet, switch the network to Preprod and create a new wallet. Save the seed phrase securely.
- Note your Unshielded address. You will paste it into the faucet in the next step.
Paste this seed phrase into .env.preprod in step 3.
Bring your own key: Any 24-word BIP-39 mnemonic or 64-hex-character seed works. The test suite derives both the shielded and unshielded keys from it.
Fund the wallet with tNIGHT and tDUST
Preprod transactions are paid in tDUST, which is generated by holding (and delegating) tNIGHT. Funding is a two-stage process:
-
Get tNIGHT from the faucet: Open the Preprod faucet, paste your Unshielded address, and click Request tokens. The faucet sends 1000 tNIGHT within a couple of minutes.
-
Delegate to start generating tDUST: Use your wallet's delegation flow to delegate your tNIGHT and begin generating spendable tDUST. The exact label varies by wallet. Without tDUST the test script fails with
Wallet.InsufficientFunds.
For faucet troubleshooting, see Get faucet tokens.
Confirm both tNIGHT and tDUST balances in your wallet before running the test. Wait until the tDUST balance is non-zero. DUST generation begins only after the network confirms the delegation transaction on-chain.
Configure .env.preprod
The repo ships with an example file. From the repository root:
cp .env.preprod.example .env.preprod
Open .env.preprod and set only one of the two variables. Delete the other line entirely. Defining both raises an error.
# Use this line if your wallet exports a 24-word phrase:
MIDNIGHT_PREPROD_MNEMONIC=word1 word2 word3 ... word24
# Or this line if you have a raw seed (hex, no 0x prefix):
MIDNIGHT_PREPROD_SEED=abcd1234... # 64 hex characters
.env.preprod privateThe file contains the secret that controls your Preprod wallet. It is already listed in .gitignore; do not commit it, share it, or paste it into chat.
Start the proof server
The proof server generates the zero-knowledge proofs the test submits to the network. On Preprod you only need the proof server itself, not the rest of the local devnet stack (the test connects to the public Preprod endpoints, so no local node or indexer is required).
In a separate terminal, from the project root:
yarn proof:up
This starts only the proof-server service from compose.yml and waits for it to become healthy on http://127.0.0.1:6300.
Run the test against Preprod
Back in your main terminal:
yarn test:preprod
The script:
- Build a wallet from the secret in
.env.preprod. - Sync the wallet against the Preprod indexer. This can take a long time on first run (the default sync timeout is 60 minutes for remote networks, versus 10 for local). The log emits one line per state emission so you can watch progress.
- Verify funds are available and register the wallet for DUST generation if not already registered.
- Deploy the
hello-worldcontract and submit a call tostoreMessage("Hello World!").
A successful run ends with output similar to:
INFO: Wallet sync complete after 23 emissions INFO: Wallet NIGHT balance on 'preprod': ... INFO: Providers initialized on 'preprod'. Ready to test! INFO: Creating private state... INFO: Setting the contract address... INFO: Contract deployed at: bba6579743ae23b44301d4a9f8df30dbd5244d63a59d8fbc2c9fc7ea521a04f8 ✓ src/test/hw.test.ts (2 tests) ✓ Hello World Contract (preprod) > Deploys the contract ✓ Hello World Contract (preprod) > Stores Hello World!
</Step>
<Step>
## Verify on the block explorer
Copy the contract address from the log line `Contract deployed at: ...` and look it up on a Preprod explorer:
- [preprod.midnightexplorer.com](https://preprod.midnightexplorer.com/)
- [midnight-preprod.subscan.io](https://midnight-preprod.subscan.io/)
The explorer shows the deploy transaction and the subsequent call transaction.
</Step>
<Step>
## Shut down
When you're done, stop the proof server:
```bash
yarn proof:down
The container exits but its image stays cached for the next run.
Troubleshooting
Wallet.InsufficientFunds: The wallet has no spendable tDUST. Confirm in your wallet that the tDUST balance is non-zero (not just tNIGHT). DUST generation only starts after the delegation transaction is confirmed.
Sync never completes: Preprod sync from a brand-new wallet can be slow. If you hit the default 60-minute timeout, raise it with the MIDNIGHT_SYNC_TIMEOUT_MS environment variable:
MIDNIGHT_SYNC_TIMEOUT_MS=7200000 yarn test:preprod # 2 hours
Set only one of MIDNIGHT_PREPROD_MNEMONIC or MIDNIGHT_PREPROD_SEED: You defined both variables in .env.preprod. Delete one.
Proof server unreachable: Check that yarn proof:up finished and http://127.0.0.1:6300 responds. If port 6300 is in use, stop the conflicting process or change the host port in compose.yml.
Deploy to Preview
The repository supports Preview with the same pattern:
- Copy
.env.preview.exampleto.env.previewand fill inMIDNIGHT_PREVIEW_MNEMONICorMIDNIGHT_PREVIEW_SEED. - Fund the wallet from the Preview faucet and delegate for tDUST.
- Run
yarn test:preview.
See Environments and endpoints for the full list of network URLs and explorers.