# Gas Metering
Make sure you have all you need before proceeding:
- You understand the concepts of gas.
- Have Go installed.
- The checkers blockchain codebase with the game wager and its handling. You can get there by following the previous steps or checking out the relevant version (opens new window).
Players can start playing checkers with your Cosmos blockchain. Transaction fees are paid by players themselves, at least the fee related to transporting the serialized bytes and the other gas-metered parts like bank
.
Next add your own gas metering to reflect the costs that different transactions impose or you can add costs to discourage spam.
# New information
These values are an inspiration but you can set your own. Save them as new constants:
# Add handling
Add a line that consumes the designated amount of gas in each relevant handler:
When handling a game creation:
When handling a move:
When handling a game rejection:
You don't meter gas in your EndBlock
handler because it is called by a player sending a transaction. It is instead a service rendered by the network. If you want to account for the gas cost of an expiration, you have to devise a way to pre-collect it as part of the other messages.
Avoid calling ConsumeGas
from within a loop. If you know the number of times your code loops, consume all the gas ahead of the loop. With this trick the transaction may run out of gas as if you had run the steps if the signer had not sent enough gas. This strategy saves computations on your node.
# Next up
Make your checkers blockchain more user-friendly by helping players avoid bad transactions via a query that tests a move. Just follow the exercise in the next section.