May 3

A perfect Sunday morning. T-shirt, jeans, and sneakers were all I need to go on a short excursion in the neighborhood. Birds chirping, grass shiny as oil paint. Clouds and sunshine gently overlook…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How I created a Cosmos Blockchain with Starport running two nodes on DigitalOcean

One of the concepts that was difficult to understand when I first started interacting with Cosmos’ Starport was the fact that the application creates a Binary file. This file can be distributed for additional peers to connect to the blockchain.

In this example, I’m going to create two servers which I will call firstNode & secondNode respectively. The first node will run thestarport serve command to build the Cosmos blockchain, create a genesis file, and the configuration. I can do this in the local environment but the purpose of this post is to get the Cosmos blockchain up and running with two nodes on DigitalOcean. I will then publish the application to Github, take a look at the automatic release process, download the release to secondNode and connect to firstnode from the secondNode.

Lastly, I will also run the blockchain locally (This part is pending as first I want to focus on two nodes onDigitalOcean).

The result will be the following:

Then create two droplets at once by selecting the add droplet button.

Once this is complete I will have two servers ready to configure.

Login to firstNode

Adding Sudo User from Usermod Command

Switch to the new user

Install Golang

Add Go to the paths in the localprofile:

At the end of the file add the following:

Refresh the profile & check version

Result:

Install Starport on the firstNode

Create Starport application on the firstNode which I will call “myblockchain”.

Start the application on the firstNode in development mode

This also runs the blockchain in development mode. If you cancel or exit this window the blockchain will stop running. You would usually run this locally when coding.

By the way, the configuration for the first two wallets, validators and faucet for the development environment lives on the config.yml.

I created a binary of myblockchain in the firstNode

This will add myblockchaind to the Go’s bin folder.

I can now start the blockchain anywhere in the system with:

Create a systemd process for myblockchaind

First, create some necessary files

Second, edit the systemd service file for myblockchaind.

Next, add the following configuration to it:

Then, enabled it to run all the time even after it reboots.

Start the process.

Lastly, I can see the logs of the new service like this:

Create a Github repo and push the code to it. This step is quite important. I will use the automatic actions from github to build a public release of the blockchain.

Create an empty github repo

Add remote and push changes

A repo with the base Starport app is now ready.

Automatic Release

The team behind Starport created a neat Github action to automatically build the application.

Go to the repo and click the Actions tab. As you can see, a git action is automatically executed once a commit is pushed to the main branch. This git action lives in .github/workflows/release.yml

This action will run the release.yml which has several steps to build and release the application.

The release in the repo contains a distribution binary for the blockchain:

Start a secondNode on DigitalOcean

Download this release and start a new node.

Login to the secondNode

Switch to the new user

Repeat step 4 & 5 (Install Go & Starport)

At this point there should be two consoles running. The firstNode with systemd and the secondNode ready for our next action.

This section will cover installing the blockchain onto another server, initialising it and then adding it to systemd.

The binary can be installed using utility from Starport. Replace the bold text with the repo’s info.

Or the repo can be cloned and built on the secondNode directly.

Initialize the node so all the necessary myblockchain files and directories get created

On this example however, I will use the scp command to copy the genesis from firstnode to secondNode, a ssh-key is needed on the firstNode

Generate a key pair for the firstNode & secondNode

Then get the public key from firstNode

Add the public key to the secondNode (at the end of the file)

Now back to the firstNode, copy the genesis from it to the secondNode.

Configure a persistent connection with the secondNode instance.

On another window in the firstNode machine run the following command to get the node-id.

Then add the firstNode node-id and IP into the configuration file on the secondNode.

Edit the server’s config.toml on the secondNode

Add a persistent connection. Use the node-id from the firstNode, IP address and default port.

Start the blockchain on the secondNode

The blockchain on secondNode is now syncing.

To verify that the nodes are connected. Open the terminal on the firstNode and run this command:

Success! the connected peers should show a number 1 which means the blockchain is successfully running on two nodes. 🎉

Finally, I’m going to add secondNode to systemd as well so that it can be running automatically at all times. This is a repeat of step 8.

Create a systemd process for myblockchaind

First, create some necessary files

Second, edit the systemd service file for myblockchaind.

Next, add the following configuration to it:

Then, enabled it to run all the time even after it reboots.

Start the process.

Lastly, I can see the logs of the new service like this:

Add a comment

Related posts:

Why Startup Companies NEED a Solid Customer Experience Strategy

Companies must start somewhere in their development, and that somewhere is as a startup. Startups are formed when someone creates a product or service that they feel solves a market need and wants to…

My House Without Children Is Missing Its Soul

I both love and hate when she is able to do things like that. I know she craves more independence, so I love it for her. I am so proud of her drive to succeed and her zest for life. At the same time…

The Secret Hacks You Should Know Before Integrating AI into Your Business

Integrating AI into your business may seem intimidating. After all, Artificial Intelligence is often seen as an advanced technology reserved for tech giants. However, this technology is open to all…