# 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 a global leaderboard.
Determine another folder for your leaderboard chain, and scaffold a chain via Ignite CLI:
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 another chain.
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
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.
- Or you can again create a separate transaction for anyone to sort and clip the leaderboard on the leaderboard chain as you did for the checkers chain.
Here you will extend the
x/leaderboard/keeper/candidate.go file in order to call for an update in
OnRecvCandidatePacket. You need to create some helper functions in
x/leaderboard/keeper/board.go and adjust the
Again, you need to include the error type in
You also need to define
Then you can include a
updateBoard call in
# 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.