Deployment using TypeScript (Windows/Linux/Mac)
Deployment on Hongbai Testnet
This guide will walk you through deploying your contract on the Hongbai Testnet. Before proceeding, ensure your development environment is set up and all prerequisites are installed. Ensure your wallet is configured and has sufficient OM test tokens to cover gas fees and contract instantiation costs.
Setting Up Your Development Environment
If you encounter any issues with your development environment setup or need to refresh your setup, follow these steps:
Install Rust:
CosmWasm contracts are written in Rust. Open your system terminal and run the following command:
Follow the prompts during installation. Choose the default installation option to install Rust on your system.
Set Rust to Stable Version:
This sets the default Rust version to stable.
Install Cargo:
Ensure Cargo is installed by checking its version:
Add WebAssembly Target:
This command adds the WebAssembly target to Rust, necessary for compiling CosmWasm contracts.
Install cargo-generate:
cargo-generate allows you to generate new Rust projects from templates.
Boilerplate Setup
We have a boilerplate where all contracts and the working directory are already set up. We just need to deploy the contract.
Clone the Repository
Check dependencies by navigating to the Cargo.toml
file in the root directory of your project. This file manages dependencies for your Rust project. Add the following dependencies:
Now our boiler plate is ready and we can go ahead with deployment on Hongbai Testnet and later verify our contract on Explorer.
Build and Deploy the Contract
Open your terminal in the project directory let’s build it using the rust optimizer with the following command:
This command will generate necessary artifacts
including the wasm
file and other required files.
Deployment Script Setup
Create a new folder named deployer to manage the deployment scripts:
Navigate to the “deployer” folder and initialize it with npm:
This sets up a new Node.js project in the deployer folder.
Install TypeScript and initialize a TypeScript configuration file:
Install the necessary dependencies for the deployment script:
Ensure your package.json
in the deployer folder includes the following dependencies:
Now, manually copy the wasm
file to the deployer folder, which was created under the artifacts folder.
Create an index.ts
file in the deployer folder with the following code for deployment script.
Remember to add your mnemonic and MANTRA Chain's RPC endpoint “https://rpc.hongbai.mantrachain.io” wherever mentioned. And don’t share your mnemonic with anyone.
Deploy the Contract
Compile TypeScript: Execute the following command to compile index.ts
. It will automatically create an index.js
file upon successful compilation:
Deploy Contract: Run the final command to deploy your CW20 contract on the MANTRA Chain. Ensure your wallet contains sufficient OM test tokens:
Once deployed, you will receive the wallet address and confirmation of contract instantiation.
Now, verify your deployment on the MANTRA Chain Explorer athttp://explorer.hongbai.mantrachain.io.
When you run the command npx ts-node index.ts
, it executes your TypeScript script for deploying a smart contract on the Hongbai Testnet. The output messages confirm various steps in the deployment process. First, the script prints the wallet address (mantra1celwechlkzqj9vh3x8vcu26fwvtct6ey5l3uvc
), indicating that the wallet has been set up correctly. Next, it confirms a successful connection to the blockchain. The contract is then uploaded, and the script provides a Code ID (401) for the uploaded contract. Finally, the contract is instantiated, and although it shows an object for the receipt, it provides the address of the instantiated contract (mantra18u93lf7jk3dc9d7dulsfdpqn5lqqzk9ee5fujle4v7y29sajelfs847jnm
). This means the contract is now deployed and live on the testnet.
Kudos!! Our CosmWasm contract is successfully deployed on Hongbai Testnet.
Last updated