Setting up your enviroment for Contract-enabled Cosmos Networks === In the last blog, we introduced CosmWasm and Cosmos SDK. In this blog we will set up the required tools. Which are - 1. Starport: A tool to ease development with Cosmos SDK 2. Wasmd: A Smart-Contract enabled Local Netowrk 3. CosmWasm Toolset: To write and compile the contracts ## Installing Starport Starport is an interface to the Cosmos SDK which lets you build networks with simple CLI commands. You can use Starport in your [browser](https://gitpod.io/#https://github.com/tendermint/starport/tree/master), but it's not recommended for this article since we will be going back and forth with the code quite a bit. If you're on Windows, try using WSL2. Install the following tools- 1. Golang >=1.16 2. Node.js >=12.19.0 3. Protocol Buffer Compiler GoLang is pretty easy to install, but make sure your version is up to date! ```shell rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.4.linux-amd64.tar.gz ``` From here, you now need to add this to the path. ```shell export PATH=$PATH:/usr/local/go/bin ``` If you thought this was easy, wait till you install NodeJS. ```shell sudo apt install nodejs sudo apt install npm ``` Finally, to install protocol buffer compiler, run ```shell apt install -y protobuf-compiler ``` You would need to install Rust. ```shell curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` Once installed, run the following to check ``` rustup default stable cargo version # If this is lower than 1.47.0+, update rustup update stable rustup target list --installed rustup target add wasm32-unknown-unknown ``` Let's now go ahead and install Starport. ``` curl https://get.starport.network/starport@v0.13.1! | bash ``` If that didn't work for you, you can also install it manuall using `make` on the [Git repo](https://github.com/tendermint/starport) and adding it into the path after solving all the errors. ## Setting up Wasmd (Option #1) Wasmd is a binary for a network that has CosmWasm enabled. When you run up a new Starport chain using `starport app <repo link>`, it does not have CosmWasm enabled by default. We will learn it towards the end, in [Preparing to deploy your contracts](https://hackmd.io/@abhinavmir/cosmwasm4). Instead of setting up a local WasmD node, you can also use the musselnet testnet. More on that in the next section. Now that we have everything needed, let's go ahead and install `wasmd`. ``` git clone https://github.com/CosmWasm/wasmd.git cd wasmd git checkout v0.14.0 make install ``` Please note that 0.14.0 is the latest release. Head over to the [repo](https://github.com/CosmWasm/wasmd/releases) to figure out the latest release during the time of your reading. Now let's check if we have installed `wasmd` correctly. ``` wasmd version ``` Finally, we need to prepare our local environment to make sure `wasmd` runs smooth. ``` # default home is ~/.wasmd # if you want to setup multiple apps on your local make sure to change this value APP_HOME="~/.wasmd" CLI_HOME="~/.wasmd" RPC="http://localhost:26657" # initialize wasmd configuration files wasmd init localnet --chain-id localnet --home ${APP_HOME} # add minimum gas prices config to app configuration file sed -i -r 's/minimum-gas-prices = ""/minimum-gas-prices = "0.025umayo"/' ${APP_HOME}/config/app.toml # add your wallet addresses to genesis wasmd add-genesis-account $(wasmd keys show -a fred) 10000000000umayo,10000000000stake --home ${APP_HOME} wasmd add-genesis-account $(wasmd keys show -a thief) 10000000000umayo,10000000000stake --home ${APP_HOME} # add fred's address as validator's address wasmd gentx --name fred --home ${APP_HOME} # collect gentxs to genesis wasmd collect-gentxs --home ${APP_HOME} # validate the genesis file wasmd validate-genesis --home ${APP_HOME} # run the node wasmd start --home ${APP_HOME} ``` Here we have configured a home directory, added a minimum gas price, added a genesis account for the genesis transaction, validated it and started the Blockchain node. With all that done, you now have set up your environment for running Smart Contracts on a CosmWasm-enabled chain. For now, we will use Wasmd, but then shift to our own Starport network. ## Using Musselnet (Option #2) For using musselnet, you'll need the following: 1. [An RPC Endpoint](https://rpc.musselnet.cosmwasm.com/status) 2. [A Faucet for MusselNet](https://faucet.musselnet.cosmwasm.com/status) - with two tokens, `ufrites` (for becoming a validator) and `umayo`. 3. Finally, a REST endpoint for Musselnet, found [here](https://lcd.musselnet.cosmwasm.com/node_info). We will also need to set up CLI. ``` source <(curl -sSL https://raw.githubusercontent.com/CosmWasm/testnets/master/musselnet/defaults.env) ``` We also need to set up Node REPL. > According to the documentations, this is out of date. ``` npx @cosmjs/cli@^0.26 --init https://raw.githubusercontent.com/CosmWasm/testnets/master/musselnet/cli_helper.ts ``` Add the keys fred, bob and thief. ```shell= # add wallets for testing wasmd keys add fred > { "name": "fred", "type": "local", "address": "wasm13nt9rxj7v2ly096hm8qsyfjzg5pr7vn5saqd50", "pubkey": "wasmpub1addwnpepqf4n9afaefugnfztg7udk50duwr4n8p7pwcjlm9tuumtlux5vud6qvfgp9g", "mnemonic": "hobby bunker rotate piano satoshi planet network verify else market spring toward pledge turkey tip slim word jaguar congress thumb flag project chalk inspire" } wasmd keys add bob wasmd keys add thief ``` Add some tokens into your wallet. ```shell JSON=$(jq -n --arg addr $(wasmd keys show -a fred) '{"denom":"umayo","address":$addr}') && curl -X POST --header "Content-Type: application/json" --data "$JSON" https://faucet.musselnet.cosmwasm.com/credit JSON=$(jq -n --arg addr $(wasmd keys show -a thief) '{"denom":"umayo","address":$addr}') && curl -X POST --header "Content-Type: application/json" --data "$JSON" https://faucet.musselnet.cosmwasm.com/credit ``` Testing out the REPL (Don't worry too much about this - yet) ```javascript // Create or load account const mnemonic = loadOrCreateMnemonic('fred.key') mnemonicToAddress(mnemonic) const { address, client } = await connect(mnemonic, {}) address client.getAccount() // if empty - this only works with CosmWasm hitFaucet(defaultFaucetUrl, address, 'FRITES') client.getAccount() ``` And we should be done! We will start with the development next article onwards!