Development Process
THORChain builds in the open—and Rujira is no exception—hence your smart contracts code will have to be open source if you build on Rujira.
Deployments on Rujira are permissioned, we look to create a coherent suite of apps and avoid duplicates. The development process includes vetting by the Rujira team, external audits and ultimately whitelisting by THORChain's node operators for mainnet deployment. Before starting to build, please contact the Rujira team to get introduced and make sure your project fits into the bigger picture and doesn't overlap with existing plans.
Make sure to check the README.md file before you start building on the App Layer, and take the time to check the commits of previous contracts deployed in the RELEASES.md file.
Start Developing
This guide will walk you through the development process for building, testing, and deploying CosmWasm contracts on Rujira. It covers everything from writing your contract, performing unit and integration testing, deploying to test environments, and finally deploying to mainnet.
1. Writing Your Contract
Rujira contracts are built using CosmWasm, a smart contract platform written in Rust. Follow the steps below to get started writing your contract:
Set up your environment: Ensure that you have Rust and the necessary development tools installed. You can follow CosmWasm's setup guide.
Contract Structure: CosmWasm contracts typically consist of the following components:
InstantiateMsg: Defines the parameters required to initialize the contract.
ExecuteMsg: Represents various actions that users can invoke on the contract.
QueryMsg: Represents read-only operations that fetch contract state.
Serialization: Contracts in CosmWasm use
#[cw_serde]
for serialization and deserialization. Rujira may introduce a modified implementation of#[cw_serde]
to provide a more compact encoding ofExecuteMsg
s, especially since these messages may be inserted into Layer 1 memos for CosmWasm callbacks. This will ensure efficient handling and smaller payloads.Best Practices:
Organize your code into modular functions for better readability and maintenance.
Use meaningful types and clear names for your messages and state variables.
Ensure that your contract handles errors gracefully and follows security best practices to prevent issues like reentrancy.
For more details on writing CosmWasm contracts, refer to the official CosmWasm documentation.
2. Testing
Before deploying your contract, it’s crucial to write and execute tests. CosmWasm provides a robust testing framework within Rust to simulate contract behavior and ensure correctness.
Unit Tests
Unit tests validate individual functions within your contract. Use these tests to check that your logic is working as expected for different scenarios, without the need for a full blockchain simulation.
Write unit tests: Add your test functions within the
tests
module in your contract.#[cfg(test)] mod tests { use super::*; // Your test cases here }
Test execution: Run your tests using the command:
cargo test
Integration Testing with Multitest
For more comprehensive testing, you can use CosmWasm’s Multitest framework, which simulates a chain environment in Rust. This allows you to test your contract’s interaction with other contracts and the chain itself.
Set up multitest: Include the
cw-multi-test
package in yourCargo.toml
dependencies.Simulate complex scenarios: Write tests that involve message execution, querying, and contract-to-contract interactions.
Run multitest: Execute your multitest suite using:
cargo test --features multitest
Multitest provides a highly realistic environment, simulating actual blockchain behavior without the need for a full node or deployment to a testnet.
3. Test Deployment
After validating your contract through unit and integration tests, the next step is deploying it to a permissionless test environment. Rujira offers two options for deploying your contract for further testing.
Localnet / Mocknet: 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 to finally build and test contracts with no reliance on external node operators. See full guide in Local Deployment Guide
Stagenet: A permissionless testnet to verify your contract in a real end-to-end environment, but with real money. Contracts will need to be tested thoroughly on Stagenet to showcase compatibility with the network and with connections to existing apps on Rujira. See a general guide on how to deploy on Stagenet with THORChain's Dev docs, and do make sure to follow the steps in Stagenet Deployment Guide
To make sure you connect to the right networks, find the overview of connections in Developer Endpoints
To check txs in a block explorer when testing on stagenet, you can find under stagenet.thorchain.net
4. Review & Audit
All contracts that want to deploy on THORChain and Rujira are subject to an internal review by a core team member and an external review by an auditor. Make sure to follow the Rujira templates for README.md and Cargo.toml.
You can find the full review process under Review and Audit Guide
5. Setup multisig as deployer address
Before you can deploy your audited contracts to mainnet, you will need to deploy a THORChain multisig address that will be used as the deployer address for your smart contracts.
Find out exactly how under Setting Up a THORChain Multisig.
6. Mainnet Deployment
Once your contract has been thoroughly tested, it’s time to deploy it to THORChain mainnet to be live officially on Rujira. This process involves additional security checks and permissions to ensure the integrity of the contract on the network.
See exactly how in Mainnet Deployment Guide
Last updated