Starport v0.17: Streamlined CLI, Improvements to Scaffolding

Denis Fadeev
Tendermint Blog
Published in
6 min readJul 16, 2021

In Starport v0.17, we’ve streamlined the command line interface and added these powerful new features:

  • A GitHub action that lets you install a chain’s binary with a single command
  • Printing of filenames that were modified and created during scaffolding
  • New flags and functionality for chain and module scaffolding commands
  • New generate commands for generating source code
  • Simplified the cmd package
  • Support for scaffolding BandChain oracle queries
  • Exposed the protoc command for advanced users

Streamlined Command Interface

We’ve improved the Starport command-line interface by restructuring the top level of the CLI in a more intuitive way to make it easier to navigate between the various features offered by Starport. The commands were reorganized in several top-level groups that correspond to functional areas: scaffold, chain, generate, network, relayer, and tools. We’ve added command aliases so you can type less and scaffold more.

Build Me a Blog-Chain

How are the commands different? They make more sense! Here’s a quick look at the Starport v0.17 commands that you use in the canonical blog example:

starport scaffold chain github.com/cosmonaut/blogcd blogstarport scaffold list post title bodystarport chain serve

Scaffold Commands

The scaffold namespace offers commands for scaffolding source code and wiring this code into the blockchain. The purpose of code scaffolding is to save developers' time by automatically creating and modifying files with boilerplate code. Scaffolding also allows a developer to quickly add code to the project that implements create, read, update, and delete (CRUD) logic for a particular data structure.

  • chain: a new Cosmos SDK chain
  • module: a new Cosmos SDK module in the x directory
  • list: CRUD for a type stored as an array, like a list of products
  • map: CRUD for a type stored as key-value pairs, like a map of account balances
  • single: CRUD for a type stored in a single place in the state, singleton
  • message: a Cosmos SDK message for triggering a state transition
  • query: a Cosmos SDK query for fetching data from a blockchain
  • packet: a Cosmos SDK message with an IBC packet for an IBC module
  • band: a BandChain oracle query for an IBC module
  • vue: a Vue 3 web app template

Every command accepts flags that customize its behavior and let you get the most out of Starport. The following examples highlight a few options of what Starport can scaffold.

A new Cosmos SDK chain without a default module:

starport scaffold chain github.com/cosmonaut/mars --no-module

To make typing commands faster, scaffold has an alias s.

A new IBC-enabled Cosmos SDK module that uses a bank keeper:

starport s module spaceport --ibc --dep bank

All the logic necessary to implement CRUD for a new spaceship type stored as key-value pairs in a particular module (spaceport), but without messages:

starport s map spaceship power:int desc --module spaceport --no-message

A Cosmos SDK message for assembling spaceships:

starport s message assemble-spaceship size:int color --module spaceport

A message with an IBC packet for launching spaceships to Earth:

starport s packet launch-spaceship spaceshipID destination --module spaceport

Chain Commands

The chain namespace contains commands for building, initializing, and starting a blockchain node in development.

  • build: build proto files, install dependencies, and compile and install node's binary
  • init: build the binary and initialize a node
  • serve: init and start a node in development with hot-reloading enabled

Generate Commands

The generate namespace is for commands that generate code from existing source code. The code generated with these commands is fully developed and is not meant to be modified by hand.

  • proto-go: generate Go source code from protocol buffer files that are required during the build process; the starport c build command generates Go automatically
  • vuex: TypeScript/Vuex client code for interacting with the blockchain API using a web browser
  • openapi: OpenAPI spec for the blockchain's API, exposed by default on localhost:1317

Other Command Namespaces

  • network: access Starport Network (currently in proof of concept phase)
  • relayer: configure a relayer and connect to other chains with IBC
  • tools: additional commands for advanced users
  • docs: Starport documentation

Integration with the BandChain Oracle

BandChain is a Cosmos SDK-based cross-chain data oracle platform that lets developers query real-world data from the modules they build. Normally, blockchains cannot access data from external sources, because it is a non-deterministic operation. However, with IBC, your blockchain’s module can make a query an oracle-blockchain (such as BandChain) that already has the data you need and return it back to your chain.

Starport now offers an easy way to add oracle-querying capability to your IBC-enabled module.

First, scaffold an IBC-enabled module (if you don’t have one already) inside a chain. Let’s call the module consuming:

starport s module consuming --ibc

Next, scaffold an oracle query inside the module. Let's call the query coinRates:

starport s band coinRates --module consuming

This command creates all the necessary code to query BandChain from your consuming module. Follow instructions in the Starport documentation to start your blockchain's node, connect it to BandChain's testnet with starport relayer, and query BandChain for token prices.

Querying for external data is an extremely useful feature that lets developers build more advanced blockchain applications that work with stock market data, real-world events, random numbers, weather, and much more.

Install Chain's Binary

The Starport chain template now includes a GitHub action that builds the chain's binary. The chain binary is built upon git push to the default branch and when a release is created on GitHub. The action essentially runs starport build that produces a binary of the node. You can then use the following curl command to install the binary without having to clone and build the project. This GitHub action feature is incredibly handy for validators of your network. Validators can skip the clone-and-build step and just download the binary directly.

curl <https://get.starport.network/USER/REPO@latest>! | bash

This command fetches and runs the script that installs the binary of your blockchain into /usr/local/bin. Learn more about the starport-installer script to know how you can use it to install a specific version of the binary.

Scaffolding Improvements and New CLI Features

Scaffold commands now print a list of modified and created files to make it easier to see how the command has affected the project.

starport s list post title bodymodify proto/mars/genesis.proto
create proto/mars/post.proto
create x/mars/client/cli/query_post.go
...
modify x/mars/handler.go
create x/mars/keeper/grpc_query_post.go
create x/mars/keeper/grpc_query_post_test.g

Since Starport v0.16, Starport is bundled with protoc, a protocol buffer compiler, and all the required proto files. In v0.17 we've exposed protoc, so it can be used, for example, to generate client-side code for other languages.

starport tools protoc

When scaffolding a chain, pass the --no-module flag to skip scaffolding of the default module that matches with the name of the project. The following command creates a chain without the x/mars module.

starport scaffold chain github.com/cosmonaut/mars --no-module

Module scaffolding now accepts --dep flag that lets you specify inter-module dependencies. This dependency feature is useful for using keeper methods from other modules, such as bank, in your custom module.

starport scaffold module foo --dep bank

The cmd package of the template has been simplified to reduce the amount of boilerplate code.

Read the full changelog in the changelog.md file.

Get Started with Starport

Are you ready to get started with Starport v0.17?

curl https://get.starport.network/starport! | bash

Do you have questions? Join our channel on Discord: https://discord.gg/vcExX9T where you’ll find an active community of Starport users and developers. Community members can help answer your questions and make launching your own Cosmos blockchain and connecting to our ecosystem even easier.

--

--