You have finished the checkers blockchain exercise. If not, you can follow that tutorial here, or just clone and checkout the relevant branch(opens new window) that contains the final version.
With your checkers application ready for use, it is a good time to prepare client elements that eventually allow you to create a GUI and/or server-side scripts. Here, you will apply what you have learned about creating your own custom CosmJS interfaces.
Before you can get into working on your application directly, you need to make sure CosmJS understands your checkers module and knows how to interact with it. This generally means you need create the Protobuf objects and clients in TypeScript and create extensions that facilitate the use of them.
You will have to create a client folder that will contain all these new elements. If you want to keep the Go parts of your checkers project separate from the TypeScript parts, you can use another repository for the client. To keep a link between the two repositories, add the client parts as a submodule to your Go parts:
Replace the path with your own repository. In effect, this creates a new client folder. This client folder makes it possible for you to easily update another repository with content generated out of your Go code.
Create a folder named scripts in your project root. This is where you will launch the Protobuf compilation. In the scripts folder install modules for the Protobuf-to-TypeScript compiler:
Create the folder structure to receive the compiled files:
$ mkdir -p client/src/types/generated
Check what Cosmos version you are using:
$ grep cosmos-sdk go.mod
This may return:
Download the required files from your .proto files:
At this point, you have the generated files in your client folder. If you have made this client folder as a Git submodule, then you can work directly in it and do not need to go back to the checkers Cosmos SDK:
$ cd client
Also, if you use Docker and did not go through the trouble of building the Docker image for the checkers Cosmos SDK, you can use the node:18.7 image.
Install the Protobuf.js package in your client project:
At a later stage, you will add checkers as an extension to Stargate, but you can define your checkers extension immediately. The canPlay query could make use of better types for player and position. Start by declaring them in client/src/checkers/player.ts:
Because the intention is to run these tests against a running chain they cannot expect too much, such as how many games have been created so far. Still, it is possible to at least test that the connection is made and queries pass through.
You may not have used Docker up to this point. The following paragraphs acquaint you with a Docker user-defined bridged network. If you plan on using Docker Compose at a later stage, having a first taste of such networks is beneficial. Docker Compose can be used to orchestrate and launch separate containers in order to mimic a production setup. If you think this could eventually be useful, you should complete this section.
To run the checkers chain with Ignite CLI you have the choice between two Docker images:
You can use the one published by Ignite themselves, for version 0.22.1: ignitehq/cli:0.22.1(opens new window). This may be faster the first time you run it, but can become annoying if you plan on doing it many times as it will download the Go dependencies every time.
This is the preferred method if you plan on using the image many times, as it downloads all Go dependencies once.
Now that you have decided which Docker image to use, you can run the tests.
Create a Docker user-defined bridge network for checkers:
$ docker network create checkers-net
Go to the checkers chain project folder. Launch the chain's container in the checkers-net network, using the DNS-resolvable name of chain-serve:
This time no ports are published (-p) back to the host. Indeed, the communication for the Node.js tests will take place within the checkers-net network.
The chain is served in a container named chain-serve. Update your client folder's .env with this information:
Again in your client folder, you can now run the tests within the same checkers-net network:
$ docker run --rm \
-v $(pwd):/client \
-w /client \
--network checkers-net \
And that is it. You defined a network over which the Node.js tests' container could easily access the chain's container.
To clean up after you have stopped the containers, you can safely delete the network:
$ docker network rm checkers-net
To summarize, this section has explored:
The need to prepare the elements that will eventually allow you to create a GUI and/or server-side scripts for your checkers application.
How to create the necessary Protobuf objects and clients in TypeScript, the extensions that facilitate the use of these clients, so that CosmJS will understand and be able to interact with your checkers module.
How to use Docker to define a network to orchestrate and launch separate containers that mimic a production setup.
† This website is maintained by the Interchain Foundation (ICF). The contents and opinions of this website are those of the ICF. The ICF provides links to cryptocurrency exchanges as a service to the public. The ICF does not warrant that the information provided by these websites is correct, complete, and up-to-date. The ICF is not responsible for their content and expressly rejects any liability for damages of any kind resulting from the use, reference to, or reliance on any information contained within these websites.