# IBC Foreign Token Wager


Make sure you have all you need before proceeding:

When you introduced a wager you made it possible for players to play a game and wager the base staking token of your blockchain application. What if your players want to play with other currencies? Your blockchain can represent a token from any other blockchain connected to your chain by using the Inter-Blockchain Communication Protocol (IBC).

You will be agnostic about the tokens that are represented and about who is taking care of the relayers. Your only concern is to enable the use of foreign tokens.

# New information

Instead of defaulting to "stake", let players decide what string represents their token. So you update:

  1. The stored game:

    Copy message StoredGame { ... string token = 13; // Denomination of the wager. } proto checkers stored_game.proto View source
  2. The message to create a game:

    Copy message MsgCreateGame { ... string token = 5; // Denomination of the wager. } proto checkers tx.proto View source

To have Starport and Protobuf recompile both files, you can use:

Copy $ starport generate proto-go

To avoid surprises down the road, also update the MsgCreateGame constructor:

Copy func NewMsgCreateGame(creator string, red string, black string, wager uint64, token string) *MsgCreateGame { return &MsgCreateGame{ ... Token: token, } } x checkers types message_create_game.go View source

You already know that you are going to emit this new information during the game creation. So add a new event key as a constant:

Copy const ( StoredGameEventToken = "Token" ) x checkers types keys.go View source

# Additional handling

You have prepared the ground by placing this token denomination into the relevant data structures. Now the proper values need to be inserted in the relevant locations:

  1. In the helper function to create the Coin in full_game.go:

    Copy func (storedGame *StoredGame) GetWagerCoin() (wager sdk.Coin) { return sdk.NewCoin(storedGame.Token, sdk.NewInt(int64(storedGame.Wager))) } x checkers types full_game.go View source
  2. In the handler that instantiates a game:

    Copy storedGame := types.StoredGame{ ... Token: msg.Token, } x checkers keeper msg_server_create_game.go View source

    Not to forget where it emits an event:

    Copy ctx.EventManager().EmitEvent( sdk.NewEvent(sdk.EventTypeMessage, ... sdk.NewAttribute(types.StoredGameEventToken, msg.Token), ) ) x checkers keeper msg_server_create_game.go View source

# Next up

In the next section you will learn how to conduct chain upgrades through migrations.