Skip to content

Contract reference

Two realms written in Gno. The rooms realm holds deposits and settles trades; the board realm only stores public listings. Amounts are in base units: 1 GNOT is 1,000,000 ugnot.

Where they live

Rooms
Not deployed on Onyx testnet yet
Board
Not deployed on Onyx testnet yet

Source and tests: gno/realms/tradewindow on GitHub.

Rooms: calls

Every call refuses coins except DepositCoins. Version rises with every change to what a side holds or who sits in it.
  • Open(counterparty string, ttlMinutes int) uint64

    Anyone. Opens a room at version 1. An empty counterparty leaves the seat open. ttlMinutes is 10 to 10080; 0 means 24 hours. Returns the room id.

  • Join(roomID uint64)

    Anyone but the maker. Takes the open seat. Raises the version.

  • DepositCoins(roomID uint64)

    A party, signing directly. Adds the coins sent with the call to your side. Raises the version.

  • DepositToken(roomID uint64, tokenKey string, amount int64)

    A party. Moves a GRC20 token from your account to the realm. Approve the realm address for the amount first, in the same transaction or before. Raises the version.

  • WithdrawCoins(roomID uint64, denom string, amount int64)

    A party. Takes coins back from your side, also after expiry. Raises the version.

  • WithdrawToken(roomID uint64, tokenKey string, amount int64)

    A party. Takes tokens back from your side, also after expiry. Raises the version.

  • Lock(roomID uint64, version uint64) string

    A party. Locks the named version, which must be the current one. If the other side already locked it, settles and returns "settled"; otherwise returns "locked".

  • Unlock(roomID uint64)

    A party. Withdraws your lock on the current version.

  • Cancel(roomID uint64)

    A party; anyone after expiry. Closes the room and sends every deposit back to its owner.

Rooms: reads

Free queries through vm/qeval. JSON amounts are strings; times are unix seconds of block time.
  • RoomJSON(id uint64) string

    One room, or null.

  • RoomsOfJSON(addr string, offset, limit int) string

    Rooms where addr is maker or taker, newest first, at most 50 per page.

  • LatestJSON(offset, limit int) string

    All rooms, newest first.

  • StatsJSON() string

    Rooms opened, settled and cancelled, settled volume per asset, pause state, realm address.

  • TokensJSON(offset, limit int) string

    Tokens in the GRC20 registry with name, symbol and decimals.

  • TokenJSON(key, owner string) string

    One token, with owner's balance and allowance to the realm.

  • Address() string

    The realm address: it holds deposits and is the spender to approve.

  • Render(path string) string

    The gno.land page: latest rooms, or room/<id>.

Refusals

A refused call changes nothing. These are the messages you can meet, word for word.
  • the room changed: review version N and lock again

    Lock named a version that is no longer current.

  • both sides need at least one asset

    Lock on a room where a side is empty.

  • waiting for a counterparty to join

    Lock before anyone took the open seat.

  • this room has expired: withdraw or cancel to get deposits back

    Join, deposit or lock after the room's lifetime.

  • only the two parties of this room can do that

    A deposit, withdrawal, lock or unlock from a third account.

  • only the two parties can cancel a room before it expires

    Cancel from a third account before expiry.

  • this room is invite only

    Join on a room opened for one address.

  • the seat is already taken

    Join after someone else joined.

  • a side can hold at most 8 different assets

    A ninth asset on one side.

  • token is not in the GRC20 registry

    DepositToken with an unknown token key.

  • this call does not take coins: use DepositCoins

    Coins sent with any other call.

  • send coins with a direct call from your account

    DepositCoins from code instead of a signed call.

  • trade rooms are paused: you can still withdraw, unlock and cancel

    Open, join, deposit or lock while paused.

Board

Listings hold no assets and promise nothing. Text with control or invisible formatting characters is refused.
  • Post(side, give, want, note string, days int) uint64

    Publishes a listing. side is buy, sell or swap; give and want up to 80 characters, note up to 280; days 1 to 30, 0 means 7. At most 10 open listings per account.

  • Close(id uint64)

    Takes your listing down.

  • OpenJSON(side string, offset, limit int) string

    Open listings, newest first, optionally one side.

  • ListingsOfJSON(owner string, offset, limit int) string

    Every listing of one owner.

  • ListingJSON(id uint64) string

    One listing, or null.

From a terminal

The same calls work without this site. Lock version 7 of room 12:
gnokey maketx call \
  -pkgpath gno.land/r/tradewindow/rooms \
  -func Lock -args 12 -args 7 \
  -gas-fee 1000000ugnot -gas-wanted 20000000 \
  -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 \
  -broadcast mykey