Development Process
Last updated
Last updated
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 file before you start building on the App Layer, and take the time to check the commits of previous contracts deployed in the file.
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.
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 .
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 of ExecuteMsg
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.
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 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.
Test execution: Run your tests using the command:
Set up multitest: Include the cw-multi-test
package in your Cargo.toml
dependencies.
Simulate complex scenarios: Write tests that involve message execution, querying, and contract-to-contract interactions.
Run multitest: Execute your multitest suite using:
Multitest provides a highly realistic environment, simulating actual blockchain behavior without the need for a full node or deployment to a testnet.
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
To make sure you connect to the right networks, find the overview of connections in API & RPC Endpoints
You can find the full review process under Review and Audit Guide
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.
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
For more details on writing CosmWasm contracts, refer to the official .
For more comprehensive testing, you can use CosmWasm’s framework, which simulates a chain environment in Rust. This allows you to test your contract’s interaction with other contracts and the chain itself.
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 , and do make sure to follow the steps in Stagenet Deployment Guide
To check txs in a block explorer when testing on stagenet, you can find under
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 for README.md and Cargo.toml.