# Create a Leaderboard Chain
In this section, you will learn:
- How to create an IBC-enabled chain that can receive information from other chains.
- How to send player scores from your extended checkers chain to a global leaderboard chain via IBC.
After the extension of the checkers chain with a leaderboard module, the checkers game can keep track of player stats and it can maintain (on request) a sorted leaderboard. In addition, it can send player stats via the Inter-Blockchain Communication Protocol (IBC) to another chain.
You will now create a leaderboard chain that can receive the
Candidate packets to store in a global leaderboard.
Create another folder for your leaderboard chain, and scaffold a chain via Ignite CLI:
Go into it:
Again, you can include an IBC-enabled leaderboard module in it:
You need a structure to keep track of player information too:
And of course a board structure:
In addition, you want to receive candidate packets:
This time you use the
--no-message flag because this chain is not going to send any player information to other chains.
As in the previous section, you need to make adjustments in the Protobuf files
proto/leaderboard/genesis.proto. Make sure to import
gogoproto/gogo.proto and use
[(gogoproto.nullable) = false]; for the
PlayerInfo and the
Board. You will also need to adjust the
x/leaderboard/genesis_test.go like you did in the previous section.
Implement the logic for receiving packets in
In addition, add a basic validation into
This calls up a new validation on the
PlayerInfo, which you also have to declare:
Now your leaderboard chain can receive player information from chains with the leaderboard module! However, you need to do some more work in order to update the board on this information.
There are two places where you can call for an update on the board structure:
OnRecvCandidatePacket, so each player sending information will pay the fee for sorting and clipping the leaderboard. This is the choice here, for simplicity.
- Or you can change your data structure a little bit and handle the sorting and clipping of the leaderboard in
Here you will extend the
x/leaderboard/keeper/candidate.go file in order to call for a leaderboard update in
OnRecvCandidatePacket. You need to create some helper functions in a new
x/leaderboard/keeper/board.go, introduce a new
Again, do not forget to declare the new error type in
You also need to define
Then you can include a call to
UpdateBoard call in
With this, your leaderboard chain is ready to update its leaderboard when receiving a candidate packet.
# Test it
You can find the sample implementation of the checkers chain extension and the leaderboard chain in this repository (opens new window). There you will also find a Docker network and the relayer settings for an easy test. It also includes a script to create and run games.
Follow the steps described in the repository to run a few tests and to see it in action. If you want to do the tests with your chains, replace
modular/b9-checkers-academy-draft with your checkers chain and
modular/leaderboard with your leaderboard chain, and build the docker images.