How-to Cosmos Pt. 1- Building a Cosmos Wallet

KagemniKarimu
Lava Network
Published in
7 min readFeb 17, 2023

Hello Cosmonauts! ⚛️

Welcome to our new blog series “Cosmos How-Tos”, where we’ll go together over basic concepts and projects you can practice to improve your skills as a Cosmos developer 🌠. Prepare for take off!! 🚀

An Introduction to the Cosmos Ecosystem

Cosmos is a decentralized network of scalable and interoperable independent blockchain ecosystems with over 53 connected chains. Using common protocols, Cosmos links different blockchains and enables them to communicate and transact with each other. One of the major advantages of Cosmos is its ability for developers to optimize design decisions to build use-specific blockchains (referred to as AppChains).

Ultimately, the goal of Cosmos is to provide a secure, fast, and efficient infrastructure for the development of decentralized blockchains and applications which intercommunicate!

At its core, Cosmos consists of three components: Tendermint Core, IBC Protocols, and Cosmos SDK. Tendermint Core is a consensus engine that allows dapps running on top of it to reach consensus quickly and reliably with finality. IBC protocols are responsible for allowing communication between blockchains built on different systems. Finally, the Cosmos SDK is an application development framework that enables developers to easily build powerful blockchain applications — without having to write a lot of code or understand complex cryptographic algorithms. It is of significant advantage for you to learn about these components if you have plans for blockchain development!

Using these components, developers can create innovative decentralized applications and blockchains that solve real-world problems in areas such as finance, healthcare, supply chain management, governance, and more. Beyond this, IBC creates a lot of opportunities for native value transfers between blockchains — empowering users and accounts in one ecosystem to execute action or provide security for an entirely different blockchain. This too leads to some pretty profound real-world consequences. Summarily, Cosmos enables users to move money or data freely across blockchains without having to worry about compatibility issues or siloed architecture.

To date, more than 150 projects have been built using the Cosmos platform — wallets like Lunie and exchanges such as Binance DEX have Cosmos to thank for their functionality! Cosmos is the fast growing host to innovative automated market making protocols such as Osmosis, secure cross chain communications protocols like Axelar, and interoperable smart contract chains like Juno. Crypto derivatives platform dYdX has even proclaimed that the Ethereum base it was built upon cannot sustain its future scaling and will switch to be entirely Cosmos-based for version 4 of their protocol. Pair this with the fact that the USDC stable coin will soon be made available on Cosmos — and you can see why there is a lot of optimism about the future of Cosmos!

Creating a Cosmos Wallet from the Command-Line

As a base user participating in the Cosmos ecosystem, you need to understand some of the basic tools that are in use. Perhaps the first thing to start with is a wallet! A Cosmos wallet is used to store, send and receive funds on the Cosmos network. Generally, a Cosmos wallet can be used across multiple cosmos chains, so it is a wise thing to create!

As per this tutorial, it can be created using Linux command-line tools such as gaiad or gaiacli. This is a useful exercise in self-custody. For further context, you can view the repository for Gaia, the Cosmos Hub SDK, here.

This tutorial requires the use of Linux and some basic understanding of the command line, but not much else! So, long as you’ve got your Terminal ready — we’re ready to get started! 🚀

To create a wallet, follow these steps:

1.

Ensure that make , gcc, and go are installed. If they’re not, you can quickly install the first two as shown below. These binaries are essential to most of the projects in the Cosmos ecosystem - so installing them now can significantly shorten your installation of other Cosmos chain daemons and binaries.

##Ubuntu##
sudo apt-get update
sudo apt-get install -y make gcc

##Fedora##
sudo dnf -y update
sudo dnf install make gcc

These steps will initiate install of gcc and make - two necessary components for our Cosmos journey. For installation of golang, see the guide available here: https://go.dev/doc/install Please be mindful that these steps may vary depending on your flavor of Linux.

2.

Download and install gaiad by running the following commands:

git clone -b v7.1.0 <https://github.com/cosmos/gaia.git>
cd gaia && make install

💡 NOTE: At the time of this tutorial v7.1.0 is the latest release of Gaia. You may need to replace the segment which says “v7.1.0” with a more recent release number. You can check the gaia github repository here.

3.

Create a wallet account using gaiad keys add [YOUR WALLET NAME HERE].This step is very important! This will create your private and public keys for your new wallet, along with an address which you can use to send and receive funds within the network. This will print as output in the terminal, that will look similar to the image below.

Below this, will appear your mnemonic. A mnemonic is more or less your password for accessing the wallet you’ve just created. You must store your mnemonic in a very safe place!

Remember — your keys🔑🔒 = your crypto💸🪙. You can consider a secure password manager or another solution!

Your public address can now be used to receive ATOM. If you’re satisfied with using your address and have stored your mnemonic in a safe place, you can conclude the tutorial here! There’s plenty to do now that you’ve got a working address and a way to take in some valuable ATOM. 🙂

Verifying your Cosmos Wallet using the Lava Gateway

Finally, you can always prove that you have a functioning wallet address on the Cosmos Hub testnet! This step is entirely optional, but a useful way to familiarize yourself with the Cosmos ecosystem and get better understanding of how Gaia works.

1.

The first step is to connect gaiad to an RPC node on the Lava gateway. You can use any public RPC - but Lava is an excellent choice because it is free, fast & Cosmos-centric. Simply login, create a new project and select COS5T as your API access.

2.

Once you have selected Cosmos Hub Testnet, you’ll need to navigate to the Cosmos Hub Testnet API Access panel and find the Tendermint/HTTP endpoint link. By default, gaiad connects to its RPC over the port 26657, which is used for Tendermint RPC. Clicking “Copy” will copy the endpoint to your clipboard. It should look like below:

This is the address of an RPC endpoint which will respond to any of our queries about the state of anything on the Cosmos Hub blockchain. I’ll refer to it as the endpoint URL for simplicity’s sake.

3.

Now, it is necessary to configure gaiad to communicate with the Cosmos Hub chain using the RPC endpoint URL you just got in the last step. This allows gaiad to query the Cosmos Hub chain and find out information about transactions and addresses.

Return to your Terminal and type the following commands:

gaiad config node <https://endpoints-testnet-1.lavanet.xyz:443/gateway/cos5/rpc-http/cdb3924c11c503a8409192cde3b911b1>
gaiad config chain-id cosmoshub-2

This tells gaiad that we’re connecting to Cosmos through our chosen endpoint. Make sure to replace the https://... address in the example above with the endpoint URL you retrieved from the Lava gateway.

4.

In order for gaiad to recognize the address created earlier, there must be a balance. In other words, you’ll need to load up your newly created wallet with some ATOM to get you started. There are numerous faucets out there which can assist you in this task, but you can join the Cosmos Network’s discord and get loaded up easily using the testnet faucet.

Once you have joined and authenticated, navigate to the #testnet-faucet channel and type $request [YOUR ADDRESS HERE] theta.

If the command completes successfully, the Testnet Faucet bot should spit out some output linking you to a copy of the transaction!

5.

You can open your terminal now and run gaiad query account [YOUR WALLET ADDRESS HERE]. gaiad will now give you a basic read out that your account exists!

That’s it!

Use your wallet to receive some funds from a faucet, or connect it to a service for payouts — not just in ATOM, but across much of the Cosmos ecosystem. Lava, for example, uses standard Cosmos bank & account modules and can be deposited in the wallet you’ve just created. For bonus points you can always try running gaiad query transaction [put TX ID FROM THE FAUCET here] using the transaction ID of the transaction you just generated with the faucet! 😃

In our next tutorial, I’ll demonstrate how you can sign and submit a transaction generated through gaiad . In the meantime, if you’ve completed this tutorial, help us by sharing it on twitter and tagging @lavanetxyz 🌋 🔥

--

--