Created on 14th December 2021
•
Terra is a powerful and revolutionary blockchain protocol that offers arguably the most sophisticated stablecoin system that exists today. It offers stable coins pegged at the price of the Dollar, Euro and Won, among others, hosted on it's own blockchain that allows for the construction of powerful decentralized applications. Terra's innovative fiat-based stablecoins, in combination with it's use of Cosmos SDK make it an ideal protocol for constructing smart contracts and decentralized applications. In this article, we'll look at building a basic smart contract in Rust using CosmWasm. CosmWasm is a smart contract compiler powered by Cosmos, which we'll deploy to the Terra blockchain. The Terra blockchain can be harnessed to easily develop and deploy smart contracts. However, due to the cutting-edge nature of the project, there are not many resources available for learning how to write these contracts, or explaining their features. Our goal with this project is to synthesize the steps we took in development, and highlight some of the core features of a CosmWasm smart contract. We explain how to deploy to LocalTerra, which allows users to easily emulate a Terra blockchain on their local machine. In addition, we provide sample code for sending messages and querying smart contracts in javascript. Our goal with this project is to pave the way for future developers to more easily understand the CosmWasm ecosystem, how to use Terra.JS, and give ourselves a better understanding of these topics in the process.
The largest hurdles we faced when developing this tutorial was the lack of resources to teach ourselves about Terra's ecosystem. We ran into problems when compiling our contract, for example there were issues with the version of CosmWasm's libraries that we were utilizing, or with querying contracts in Terra.JS, and the only way we could really fix our issues were trial and error. This project originally intended to be much more ambitious with our development - We had planned to build out a forked version of TerraSwap, Terra's most popular Decentralized Exchange. However, as we began development, we realized that there was an astounding lack of resources on development with CosmWasm and Terra, and so we pivoted to alleviate this pain point. While documentation was at times convoluted for the technology used, in practice CosmWasm and Terra.js provide very elegant and easy to develop solutions.
Technologies used