Token rules without code
Describe pausable, freeze, allowlist, and royalty rules in a JSON policy, and the generator emits a deploy-ready controller contract. No JavaScript required.
"A VM that runs JavaScript" is an abstract claim, so here is the concrete version: fourteen working contract templates, from a two-party escrow to an automated market maker, each one plain JavaScript, MIT-licensed, tested against the real VM, and documented down to the attacks it considers. Fork one instead of starting from a blank file.
Live today onBitcoin·Litecoin·Dogecoin·more chains coming
The shape of a contract
A contract is a JavaScript module: initialize is its constructor, every other exported function is a method someone can call with EXECUTE, and tokens move in and out of its custody with DEPOSIT and WITHDRAW. No new language, no compiler, no toolchain to install first.
This is the settlement path of the escrow template, abridged from the real 215-line contract. Three habits every template shares are visible right here:
SEND, and the same validated handler that checks every user transaction checks this one.Every template's README walks through its custody model the same way, and closes with the attacks it was written to survive.
// escrow.js (abridged): pay the seller. The buyer can release,
// or the arbiter can, to settle a dispute.
release: function (xchain) {
settle(xchain, ['buyer', 'arbiter'], 'seller', 'RELEASED');
},
function settle(xchain, allowedRoles, payeeRole, terminalStatus) {
xchain.require(xchain.state.get('status') === 'FUNDED',
'escrow not funded / already settled');
// Only the roles fixed at deploy time may settle.
var caller = xchain.getSourceAddress();
var ok = isAllowed(caller, allowedRoles);
xchain.require(ok, 'not authorized');
// Never trust a caller-supplied amount: read the chain.
var tick = xchain.state.get('tick');
var addr = xchain.getContractAddress();
var held = xchain.getBalance(addr, tick);
xchain.require(xchain.math.gt(held, '0'), 'nothing to settle');
// Mark terminal BEFORE paying: no second payout.
xchain.state.set('status', terminalStatus);
// The contract can't touch the ledger. It emits a validated SEND,
// checked by the same handlers as every user transaction.
xchain.emit.send({
destination: xchain.state.get(payeeRole),
tick: tick,
quantity: held
});
}
The library
Each template lives in its own folder with the contract, its test suite, and a README that explains the custody model and the attacks it considers. All of it is MIT-licensed, so a fork can become your product. Click any card to read the code.
A buyer locks tokens for a seller, with an arbiter and a deadline for disputes. The recommended first read.
Ascending bids, where each new high bid refunds the outbid bidder in the same transaction.
The price falls linearly to a floor; the first buyer willing to pay wins at that price.
A constant-product AMM with a 0.3% fee whose LP shares are real, tradeable tokens the contract issues itself.
A capped token sale with a soft cap and deadline, where the contract creates and issues its own token.
Linear release with a cliff, measured in blocks, with optional revocation for the unvested remainder.
A poll-governed treasury with a timelock and a guardian veto, hardened against low-turnout raids.
Random card packs drawn from the contract's real inventory, with rarity set by what is actually in stock.
A two-party binary option settled by the PRICE oracle at an agreed round, with deterministic settlement anyone can trigger.
The same bet settled by the first oracle round at or after an agreed clock time instead of a round number.
An over-collateralized stablecoin engine with oracle staleness gating and permissionless liquidation.
Escrow that releases itself when a carrier's tracking page attests delivery: no manual settlement call.
Read an HTTPS endpoint from a contract through validator attestation, without breaking determinism.
Burn-to-mint migration for Counterparty assets, minting only after attestation confirms the burn is irreversible.
More than examples
The repository is also the starter kit: shared building blocks, a generator for the most common contract, and the same checks the chain will run at deploy time.
Access control, pausable, safe transfer, state machine, and validation: five building blocks, each small enough to paste into your own contract.
Describe pausable, freeze, allowlist, and royalty rules in a JSON policy, and the generator emits a deploy-ready controller contract. No JavaScript required.
npx xchain-contracts scaffold starts a new contract from any template, and the linter runs the deploy-time rules before the chain does.
Every template ships its own test suite, executed in the same sandboxed VM that validators run, not in a lookalike harness.
Go deeper
The safety model in plain English: why a contract bug cannot drain the ledger or mint from thin air.
DEPLOY, EXECUTE, DEPOSIT, WITHDRAW, and XCALL: the five ACTIONs every contract on this page is built from.
Step-by-step guides: build your first token, a dispenser, a stakeable contract, and a regtest development loop.
The SDK deploys, executes, and watches contracts in a few function calls, on any supported chain.