# Cosmwasm with Testnet & Beaker
# Deploying Cosmwasm Contracts to the testnet with Beaker
The following guide will show you how to create and deploy a Cosmwasm smart contract to the Osmosis testnet. The testnet is permisonless by default to allow developers to test their contracts on a live environment. The Osmosis mainnet is permissioned meaning that you will need to submit a governance proposal in order to deploy to it.
# Requirements
# Install Beaker
Beaker is available via cargo (opens new window) which is a rust toolchain. Once cargo is ready on your machine, run:
cargo install beaker
# Scaffolding your new dapp project
In the directory you want your project to reside, run:
beaker new counter-dapp
For detailed information about Beaker click here (opens new window).
# Your first CosmWasm contract with Beaker
After that we can create new contract (the command uses template from cw-template (opens new window))
cd counter-dapp
beaker wasm new counter
2
# Deploy contract on permisionless network
The testnet is permisionless by default in order to allow developers to easyly deploy contracts.
beaker wasm deploy counter --signer-account test1 --network testnet --no-wasm-opt --raw '{ "count": 0 }' --label 'My first Beaker Contract'
Note how we added --network testnet
to tell beaker to deploy to the testnet Osmosis chain.
# Deploy with an admin
In this example we are using osmo1nyphwl8p5yx6fxzevjwqunsfqpcxukmtk8t60m
which is the address from the beaker test1 account as seen in the config.rs (opens new window) file.
WARNING
Please note that account test1 is publicaly available as documented here (opens new window) and only used for development purposes. Beaker will support local keyring in about 1-2 weeks.
beaker wasm deploy counter --signer-account test1 --admin osmo1nyphwl8p5yx6fxzevjwqunsfqpcxukmtk8t60m --network testnet --no-wasm-opt --raw '{ "count": 0 }' --label 'My first Beaker Contract'
# Deploy contract via governance
We can also deploy the contract via governance on the testnet before going to mainnet. There are a couple of steps as described in the manual process via CLIhere (opens new window), more details also available on the official CosmWasm Docs (opens new window).
# Build contract
This is required to create the compiled.wasm file that will be uploaded to the block chain.
beaker wasm build
# Submit proposal
The proposal can be submitted with all the meta data in a yml file or toml file. Example file:
touch prop.yml
nano prop.yml
2
Paste the following template
title: Proposal to allow DappName to be enabled in Osmosis
description: |
A lengthy proposal description
goes here
we expect this to be many lines...
deposit: 500000000uosmo
code:
repo: https://github.com/osmosis-labs/beaker/
rust_flags: -C link-arg=-s
roptimizer: workspace-optimizer:0.12.6
2
3
4
5
6
7
8
9
10
beaker wasm proposal store-code --proposal prop.yml --signer-account test1 --network testnet counter --gas 25000000uosmo --gas-limit 25000000
# Query proposal
There are four ways to query the proposal results
- Beaker command
beaker wasm proposal query store-code --network testnet counter
- Osmosisd
osmosisd query gov tally 196
- Mintstan testnet explorer
https://testnet.mintscan.io/osmosis-testnet/proposals/196
- LCD Proposal endpoint
https://lcd-test.osmosis.zone/cosmos/gov/v1beta1/proposals/196
Note how the min_deposit was 500000000uosmo
that's why our prop.yml had 500000000uosmo
. If the deposit requirement is not met, then additional funds need to be send to the proposal.
# Proposal period
On the testnet the voting period is very short to allow developers to move quickly with their testing, as you can see in this case it's 3 minutes
. This means you must vote within the next 3 minutes for your proposal to pass. In mainet the voting period is usually several days. If you take longer than 3 minutes, then you will get an error letting you know that the voting period has passed.
├── voting_start_time: 2022-07-06T18:45:06Z
└── voting_end_time: 2022-07-06T18:48:06Z
2
# Voting on proposal on testnet
Run the following command to vote from beaker
beaker wasm proposal vote --option yes counter --signer-account test1 --network testnet
Even though the testnet is configured as permisionless, it's important to undertanding the voting process. We need validators to vote for your proposal in order to reach the quorum. We created a simple utility in our faucet that will allow you to request a validator with enough voting power to vote for your proposal as well.
Please visit:
https://faucet.osmosis.zone/#/contracts (opens new window)
Great! Your proposal should have passed now!
# Signers
In the examples above we used the test1 account to sign transactions. However, Bekaer supports 3 options for signing transactions as shown on the official README (opens new window).
--signer-account
input of this option refer to the accounts defined in the config file, which is not encrypted, so it should be used only for testing--signer-mnemonic
input of this option is the raw mnemonic string to construct a signer--signer-private-key
input of this option is the same as--signer-mnemonic
except it expects base64 encoded private key--signer-keyring
use the OS secure store as backend to securely store your key. To manage them, you can find more information here.
This document is constantly being updated and improved, please let us know on Github if you have any questions!