MANTRA Chain
  • Introduction
    • Overview
    • Why MANTRA Chain
    • Building on MANTRA Chain
    • MANTRA RWA Suite
  • Using MANTRA Chain
    • MANTRA Chain Wallet Setup
      • Connect to Testnet
      • Connect to Mainnet
      • Testnet Faucet
    • MANTRA Zone
    • MANTRA Bridge
      • MANTRA Bridge User Guide
      • MANTRA Bridge FAQs
    • Stake
      • Stake User Guide
      • Stake FAQs
    • MANTRA Swap
      • MANTRA Swap User Guide
      • Liquidity Pools User Guide
      • MANTRA Swap FAQs
    • Claiming Journey
      • Check If You're Eligible
      • Claiming Journey User Guide
      • I've redeemed my rewards, now what?
    • Chakra Pool
      • What can I do with my USDY
      • Chakra Pool Deposit Guide
      • How KARMA works for Chakra Pool
        • How much KARMA do I get for depositing into Chakra Pool?
        • Can I make multiple deposits and how will KARMA be calculated then?
        • My KARMA is not updated even though I make multiple deposits?
        • Will I get daily KARMA for my deposit on USDY Chakra Pool launched on Hongbai earlier?
      • Chakra Pool FAQs
    • MANTRA Zone Leaderboard
      • MANTRA Zone Leaderboard User Guide
        • Mission Guides
          • Pledge your OM ๐Ÿ•‰๏ธ
          • Claim OM Staking Rewards
          • OMly Drip ๐Ÿ’ง
      • MANTRA Zone Leaderboard FAQs
  • Developing on MANTRA Chain
    • Getting Started
      • DuKong Testnet
      • Install Prerequisites
      • Setting Up Dev Environment
      • Compiling a Contract
      • Deployment and Interaction
    • CosmWasm Quick Start Guide
      • CosmWasm Contracts
      • Understanding CosmWasm File Structure
    • DAPP Tooling
      • Cosmos SDK
      • Important Libraries
      • Developer Resources
    • Developer FAQs
  • MANTRA Smart Contracts
    • Overview
    • MANTRA Dex
      • ๐ŸšขDeployments
      • ๐Ÿ“šCommon Types
      • ๐Ÿ’ฐFee Collector
      • โŒ›Epoch Manager
      • ๐ŸŒŠPool Manager
      • ๐ŸŽFarm Manager
    • Claimdrop Contract
    • Audits
  • Node & Validator Operations
    • Overview
    • Node Setup & Deployment
      • Node System Requirements
      • Running a Node
      • How to run Mantrachain with Systemd
      • Validator Nodes
        • Connect sidecar
    • Validator Architecture Recommendations
      • Secure Validator
    • Governance
      • Draft a Proposal
        • Text Proposal
        • Community Spend Proposal
        • Software Upgrade
        • Cancel Software Upgrade
      • Submitting a Proposal
      • Verifying your transaction
      • Depositing funds
      • Voting on a Proposal
    • Download nodes snapshots
  • MANTRA Chain with EVM (Alpha)
    • Getting Started on OMSTEAD Testnet
  • Setup Instructions
  • Using Foundry
    • Deployment with Foundry
  • Using Hardhat
    • Deployment with Hardhat
  • Mainnet OM Information
    • Background
    • Updated OM Tokenomics
    • OM Distribution Updates
    • Inflation & Vesting Schedule
    • Legacy tokens to mainnet staking tokens
  • Appendix
    • Frequently Asked Questions
      • General FAQs
        • What is MANTRA Chain?
        • What are the key features/ modules available to builders on MANTRA Chain?
        • What support is available for developers and validators that join the ecosystem
        • Where can i find MANTRA Social Accounts & Communities?
        • How can an Issue or a bug be reported?
        • How can I identify official MANTRA communication and websites?
      • Validator FAQs
        • What does a new validatorโ€™s journey look like?
        • What are my key responsibilities as a validator?
        • What is uptime and how is it maintained?
        • What are the hardware requirements?
        • How to get validator keys?
        • How can I connect a validator from an older testnet to the newest testnet?
        • How do I create a backup snapshot of a node?
        • How do I restore a node from a snapshot?
        • What are the different states a validator can be in?
        • How do I unjail a validator?
        • How do I edit a validator's description?
        • What is self-delegation?
        • Is there a minimum amount of OM that must be delegated to be an active validator?
      • Developer FAQs
        • What is MANTRA Chain, and how does it utilize the Cosmos ecosystem?
        • How does MANTRA Chain ensure interoperability with other blockchains in the Cosmos ecosystem?
        • What is the Cosmos ecosystem, and how does it differ from other blockchain platforms?
        • Which programming languages are commonly used for developing on the Cosmos ecosystem?
        • How do I get started with development on the Cosmos ecosystem?
        • What are Cosmos SDK and Tendermint, and how do they work together?
        • What are Cosmos zones and how do they interact?
        • How do I build and deploy smart contracts on the Cosmos ecosystem?
        • How do I interact with Cosmos chains and applications programmatically?
        • What is the best way to learn about developing for the MANTRA Chain and Cosmos ecosystem?
      • Hongbai FAQs
        • Where do I sign up for Hongbai?
        • Why do I need to provide 2 wallets during signup?
        • How can I Login?
        • What should I do if I forgot my password?
        • What can I do if i forget my registered email?
        • Where do i verify my email?
        • How to connect my Metamask wallet?
        • Is Hongbai app a testnet or live app?
        • Can I change my wallet ?
        • Error โ€œinvalid user credentialsโ€œ
        • Why can i not Invest?
      • How to Guides
        • Install Keplr Wallet
        • Keplr and Ledger
        • Add DuKong Testnet to Keplr
        • Get Tokens from Faucet
        • Track activity on Leaderboard
      • More Help & Support
      • MANTRA Zone FAQs
        • MANTRA Zone General FAQs
          • What wallets are currently supported on the MANTRA Zone?
          • How do I connect my wallet to the MANTRA Zone?
          • How do I copy my connected walletโ€™s address?
          • How do I connect a different wallet to the MANTRA Zone?
          • Can I disconnect my wallet from MANTRA Zone?
          • How can I resolve seeing multiple entires of the same amount of testnet OM in my Keplr wallet?
          • The question that I have is not covered by the FAQ, what should I do?
        • MANTRA Bridge FAQs
          • What is MANTRA Bridge?
          • Why should I use the MANTRA Bridge?
          • Is there a fee for using the MANTRA Bridge?
          • Do I have to pay gas fees?
          • What tokens will I receive?
          • How does the migration process work?
          • How long should the MANTRA Bridge order take?
          • How can I track the status of my MANTRA Bridge order?
          • What happens to my ERC20 OM tokens once I use the MANTRA Bridge?
          • Which network can I use on the MANTRA Bridge?
          • What should I do if I see โ€˜Wrong networkโ€™ error on the app?
          • Will there be a two-way bridge in the future?
          • My MANTRA Bridge order is stuck on Ethereum?! How can I fix this?
          • Who can I contact for support during the migration process?
          • Which EVM chains can I bridge from?
          • Are the OM tokens I receive wrapped tokens or the native MANTRA Chain OM tokens?
          • Is the MANTRA Bridge a non-custodial solution?
          • What happens if the MANTRA Bridge is hacked or goes offline?
          • Are there any risks associated with using the MANTRA Bridge?
          • How does the MANTRA Bridge ensure the security of my tokens during migration?
          • Can I use my existing Ethereum wallet to access the MANTRA Bridge?
          • How does wallet linking and airdrop participation work?
        • Stake FAQs
          • What is Stake?
          • What are validators, and how do I choose one?
          • What rewards can I earn by staking $OM?
          • How are staking rewards calculated?
          • Can I choose to unstake my $OM coins?
          • What is the unbonding period?
          • Can I change validators after staking $OM?
          • Can I stake $OM with multiple validators?
          • Are there any risks involved with staking $OM?
          • Will my rewards gets automatically restaked after redemption?
          • Do I lose my claimable rewards when performing actions with a validator with unclaimed rewards?
          • My wallet is showing a 0 balance even though I have funds. What should I do?
          • How do I know if my $OM is staked?
        • Chakra Pool FAQs
          • What are the Chakra Pool rewards?
          • What is USDY?
          • How do I get the yield from the treasury bonds by holding USDY?
          • Can I change my linked wallet?
          • I donโ€™t remember my linked wallet - what can I do?
          • What are the bonus rewards and where I can see my rewards?
          • How are the USDY rewards calculated and when can I redeem my USDY rewards?
          • How are the $OM rewards calculated and when can I redeem my $OM rewards?
          • How are the $ONDO rewards calculated and when can I redeem my $ONDO rewards?
          • What can I do with my USDY and $OM rewards after redemption?
        • MANTRA Zone Leaderboard FAQs
          • I have someone that wants to participate in the MANTRA Zone Leaderboard but they donโ€™t know how.
          • What does the โšกicon and โ€˜Get + x KARMAโ€™ text under the โ€˜KARMAโ€™ section refer to?
          • The KARMA on the Zone Leaderboard only lists MANTRA Chain wallets, how to check my EVM wallet rank?
          • Which wallet IDs are visible on the Leaderboard Ranking Table?
          • Why are there three different categories for the Leaderboard Ranking Table?
          • How can I get the Leaderboard Ranking Table to show where my connected wallet ranks currently?
          • How can I search where a specific wallet ID ranks in the Leaderboard Ranking Table?
          • How can I search what wallet ID currently ranks in a specific ranking number?
          • My KARMA and/or multiplier amount did not update on the Leaderboard Ranking Table, why is that?
          • What is the calculation for the KARMA?
          • Iโ€™m unable to see the OMly Faucet on my Keplr/Cosmostation wallet
          • I'm unable to see my OMly Faucet Claim transaction on the explorer
          • The question that I have is not covered by the FAQ, what should I do?
        • MANTRA Swap FAQs
          • What is Swap?
          • How can I swap?
          • I have connected my EVM wallet, but Iโ€™m still unable to swap. Why?
          • Where can I view my past transactions?
          • Why is my swap button disabled?
          • Why canโ€™t I swap with a slippage more than 5%?
          • What is Exchange Rate?
          • How do I get OM tokens in my wallet?
          • How do I get other tokens in my wallet?
          • Will the swap fee be deducted from my sell or buy token?
          • Why canโ€™t I see the balance of tokens in my wallet but on the Swap panel?
          • How do I add liquidity to a pool?
          • I am unable to provide liquidity to the pool.
          • While adding liquidity, why are the two tokens USD value not equal?
          • How do I withdraw my funds from Liquidity Pools?
          • Why can I not see my tokens for withdrawal?
          • Why can I not remove liquidity?
          • Why is my deposited value of the two tokens changing in my position?
          • Do liquidity pools have a bonding period?
          • What are LP tokens?
          • What can I do with my LP tokens?
          • Why can I not see any LP token balance?
          • I am connected with my MANTRA wallet, but still cannot view my positions?
          • I provided liquidity, but I canโ€™t see my position. What should I do?
          • Why is my transaction not successful?
    • Glossary
    • MANTRA's Incentivised Testnet
      • Testnet Phase 1
      • Hongbai - Testnet Phase 2
  • Third Party Bridges
    • Base Bridge
    • Polygon Bridge
Powered by GitBook
On this page
  • Deployment on DuKong Testnet
  • Boilerplate Setup
  1. Developing on MANTRA Chain
  2. Getting Started

Deployment using TypeScript (Windows/Linux/Mac)

Deployment on DuKong Testnet

This guide will walk you through deploying your contract on the DuKong 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:

  1. Install Rust:

CosmWasm contracts are written in Rust. Open your system terminal and run the following command:

$ curl --proto '=https' --tlsv1.2 <https://sh.rustup.rs> -sSf | sh

Follow the prompts during installation. Choose the default installation option to install Rust on your system.

  1. Set Rust to Stable Version:

$ rustup default stable

This sets the default Rust version to stable.

  1. Install Cargo:

Ensure Cargo is installed by checking its version:

$ cargo --version
  1. Add WebAssembly Target:

This command adds the WebAssembly target to Rust, necessary for compiling CosmWasm contracts.

$ rustup target add wasm32-unknown-unknown
  1. Install cargo-generate:

cargo-generate allows you to generate new Rust projects from templates.

$ cargo install cargo-generate --features vendored-openssl

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

git clone <https://github.com/MANTRA-Finance/contract_deploy.git>

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:

[dependencies]
cw20-base = {  version = "0.13.2", features = ["library"] }
cw20 = "2.0.0"
cw-utils = "0.12.1"
cosmwasm-std = "1.0.0"
cosmwasm-storage = "1.1.1"
cw-storage-plus = "0.15.0"
cw2 = "0.15.0"
schemars = "0.8.10"
serde = { version = "1.0.144", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }
cosmwasm-schema = "1.1.4"
prost = "0.12"

Now our boiler plate is ready and we can go ahead with deployment on DuKong 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:

docker run --rm -v "$(pwd)":/code \\
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \\
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \\
  cosmwasm/optimizer:0.16.0

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:

mkdir deployer

Navigate to the โ€œdeployerโ€ folder and initialize it with npm:

cd deployer

npm init -y

npm i

This sets up a new Node.js project in the deployer folder.

Install TypeScript and initialize a TypeScript configuration file:

npm install typescript --save-dev

npx tsc --init

Install the necessary dependencies for the deployment script:

npm install @cosmjs/cosmwasm-stargate

npm install @cosmjs/proto-signing @cosmjs/stargate dotenv fs

Ensure your package.json in the deployer folder includes the following dependencies:

"dependencies": {
    "@cosmjs/cosmwasm-stargate": "^0.32.4",
    "@cosmjs/proto-signing": "^0.32.4",
    "@cosmjs/stargate": "^0.32.4",
    "dotenv": "^16.4.5",
    "fs": "^0.0.1-security"
  }

Now, manually copy the wasm file to the deployer folder, which was created under the artifacts folder.

Create an index.tsfile in the deployer folder with the following code for deployment script.

const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const {
  assertIsBroadcastTxSuccess,
  SigningCosmWasmClient,
  CosmWasmClient,
} = require("@cosmjs/cosmwasm-stargate");
const { coins, GasPrice } = require("@cosmjs/stargate");
const fs = require("fs");
require("dotenv").config();

 const mnemonic = process.env.MNEMONIC; // Replace with your mnemonic
// const rpcEndpoint = process.env.RPC; // Replace with your RPC endpoint
const rpcEndpoint = "<https://rpc.dukong.mantrachain.io>";
const contractWasmPath = "./dinonum.wasm"; // Path to your compiled contract(wasm file )

async function deploy() {
  // Step 1: Set up wallet and client
  const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
    prefix: "mantra", // Replace with the correct prefix for your chain
  });
  const [account] = await wallet.getAccounts();
  console.log(`Wallet address: ${account.address}`);

  // Step 2: Connect to the blockchain
  const client = await SigningCosmWasmClient.connectWithSigner(
    rpcEndpoint,
    wallet,
    { gasPrice: GasPrice.fromString("0.01uom") }
  );
  console.log("Connected to blockchain");

  // Step 3: Upload contract
  const wasmCode = fs.readFileSync("./dinonum.wasm");
  const uploadReceipt = await client.upload(
    account.address,
    wasmCode,
    "auto",
    "Upload CosmWasm contract"
 );
  const codeId = uploadReceipt.codeId;
  console.log(`Contract uploaded with Code ID: ${codeId}`);

  // Step 4: Instantiate contract
  const initMsg = {
    count: 10,
  }; // Replace with your contract's init message
  const instantiateReceipt = await client.instantiate(
    account.address,
    codeId,
    initMsg,
    "My Dinonum Contract",
    "auto"
  );
  const contractAddress = instantiateReceipt.contractAddress;
  console.log(`Contract instantiated at reciept: ${instantiateReceipt}`);
  console.log(`Contract instantiated at address: ${contractAddress}`);
}

deploy().catch(console.error);

Deploy the Contract

Compile TypeScript: Execute the following command to compile index.ts. It will automatically create an index.js file upon successful compilation:

tsc index.ts

Deploy Contract: Run the final command to deploy your CW20 contract on the MANTRA Chain. Ensure your wallet contains sufficient OM test tokens:

npx ts-node index.ts

Once deployed, you will receive the wallet address and confirmation of contract instantiation.

When you run the command npx ts-node index.ts, it executes your TypeScript script for deploying a smart contract on the DuKong 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 DuKong Testnet.

Last updated 6 months ago

Remember to add your mnemonic and MANTRA Chain's RPC endpoint โ€œโ€ wherever mentioned. And donโ€™t share your mnemonic with anyone.

Now, verify your deployment on the MANTRA Chain Explorer at .

https://rpc.dukong.mantrachain.io
https://explorer.mantrachain.io