Add an in-game currency
A game currency in one function call, with balances on a chain instead of in a database you operate. balanceOf answers in a single call, and you never write a migration.
You are probably here because somebody asked for
- add an in-game currency to my game
- add coins / gems / credits players can earn and spend
- give my game a soft currency without a backend
Status: M1 of eleven. The SDK is real and runs end to end. The chain underneath it is an in-memory mock — there is no public network yet, and nothing anywhere holds value.
The usual version of this task is a balances table, a service in front of it, an audit trail, and a permanent worry about double-spends and rollbacks. The currency is the easy part; operating a ledger correctly is the work.
On Kei the ledger is consensus. You issue the token and the chain holds the balances.
const gems = await game.token.issue({
name: 'Gems',
symbol: 'GEM',
decimals: 0,
maxSupply: 1_000_000, // optional; caps circulating supply
transfer: 'open', // 'open' | 'issuer-only' | 'none' — protocol-enforced
swap: 'one-way', // a promise to players, recorded on-chain
rate: 100, // your desk's price. Never on-chain, so you can change it.
})
await gems.mint(playerAddress, 500)
await gems.balanceOf(playerAddress) // 500 — one callThe one decision that matters
transfer is immutable and enforced by the protocol, not by your code. It is the only real mechanism for a closed economy, and it cannot be changed after issuance.
| Value | What it means | Choose it when |
|---|---|---|
| open | Players can trade with each other. A permissionless market can and eventually will appear. | You want a real economy, and you accept you will not control the secondary market. |
| issuer-only | Players genuinely cannot trade with each other. Not "we discourage it" — they cannot. | You need a closed economy and mean it. |
| none | Soulbound. Units can only be burned. | Achievements, reputation, anything that should not have a price. |
What it costs
Issuing burns 1,000 Kei. It is the one operation that is not free, because an asset record is permanent state on every node forever. Every transaction after that — minting, sending, transferring, claiming — is free, always.
Give the currency a sink. A currency that is only ever minted inflates, and that is a design problem no chain fixes for you.
What is not true yet
- The chain is an in-memory mock today. The API is real and does not change when the node lands, but nothing on it holds value and there is no public network yet.
- The issuer seed must stay on a server.
Kei.server()refuses to run in a browser, because an issuer seed in a client is unlimited minting by anyone who views source. - There is no exchange, no AMM, and no order book in the protocol.
rateis your own configuration, not a market.