Skip to main content

Overview

Cowboy has protocol-native fungible tokens (CIP-20): token state lives in the chain’s state tree and is manipulated through system instructions, not per-token smart contracts. You interact with tokens two ways:
  • From the CLIcowboy token <subcommand> for scripting and operations
  • From actor coderuntime.token_* host functions, so actors can create and move tokens as part of their logic
Amounts are integers in the token’s base unit (u128); decimals is display metadata only.

From the CLI

The full command surface is specified in cowboy token. A typical lifecycle:

From actor code

Actors get the same operations through cowboy_sdk.runtime. The caller is the actor itself — the actor’s address is the token owner / sender of transfers:
The query/move surface mirrors the CLI: Each operation has a fixed gas cost (e.g. a transfer is 1,000 Cycles + 64 Cells) — see CIP-20 for the schedule.

Transfer hooks

A token can name a hook actor at creation (transfer_hook) to enforce custom transfer policy — blocklists, pausing, compliance logic. The hook implements two handlers:
  • can_transfer(payload) — called before balances move. Runs read-only (state writes are not committed). The check is fail-closed: the transfer proceeds only if the hook returns "true", "1", or JSON true; any other output (including b"ok" or an error) rejects it, reverting with TokenHookRejected.
  • on_transfer(payload) — called after balances move, and may update the hook actor’s own state. Best-effort: a failure here is logged but does not revert the transfer.
Both receive a JSON payload:
Hooks run under hard sub-limits (token_hook_max_cycles / token_hook_max_cells, 50,000 each) regardless of the transaction’s gas budget — keep them small. Hook reentrancy into the same token is blocked by the runtime.

Worked example

examples/core/05-tokens-and-balances/ in the repo pairs a CLI walkthrough (demo.sh) with an actor that creates and transfers a token programmatically (token_actor_example.py) — a good starting template for both styles.

Further reading