Trade
Two players trade directly: they open a trade, each puts items and money in on their own side, and each confirms. When both have confirmed, each side receives what the other put in. Either side may cancel while the trade is open, and each side then takes back what it put in. No fee is taken. Requires Inventory.
const deal = await rudder.trade.open({ partner: '01a1-…' });
await rudder.trade.pay({ trade: deal.trade, money: { asset: 'gold', amount: 200 } });await rudder.trade.confirm({ trade: deal.trade });Functions
Section titled “Functions”| Function | Kind | Caller | Arguments | Result |
|---|---|---|---|---|
open | mutation | client | {partner} | The trade, with its trade id |
offer | mutation | client | {trade, item, count?, id?} | The trade |
pay | mutation | client | {trade, money} | The trade |
confirm | mutation | client | {trade} | The trade |
cancel | mutation | client | {trade} | The trade |
view | query | client | {trade} | The trade |
open names the player on the other side; the caller is the first side. offer takes tradable
goods out of the caller’s inventory into its side; count is how many of a stackable item (1 by
default) and id names one unique piece instead of item. pay takes money out of the caller’s
wallet into its side, in any asset, as often as the player likes.
A trade has trade (its id), status (open, settled or cancelled) and two sides in the
order they were opened, each with player, goods, money, confirmed and claimed. The id is
the only handle of a trade: the module does not list the trades of a player, and the other side is
told nothing.
How a trade runs
Section titled “How a trade runs”- A side confirms what it sees. One confirmation settles nothing: the trade stays open with that
side marked
confirmed. - Any
offerorpayby either side clears both confirmations, so nothing can be added under a side that has already confirmed. - When both sides have confirmed the trade settles: each side receives the other side’s goods and money.
cancelis allowed to either side while the trade is open, whatever is deposited, and always gives each side its own goods and money back. A trade is therefore never binding until it settles.- Deposits cannot be taken back one by one; undoing one means cancelling the whole trade.
- Nothing expires: an open trade and its deposits wait until someone acts.
Errors
Section titled “Errors”| Code | Meaning |
|---|---|
no_trade | There is no such trade, or it is finished and both sides have collected. |
not_party | The player is not a side of the trade. |
closed | The trade is settled or cancelled. |
own_trade | A player does not trade with themselves. |
invalid_amount | An amount of money must be positive. |
insufficient | The player does not hold the money of pay. |
unknown_item, not_tradable, invalid_count, not_enough, stack_full | From Inventory. |
Events
Section titled “Events”| Event | Payload | When |
|---|---|---|
settled | {trade} | Both sides confirmed; each side collects the other’s deposit. |
cancelled | {trade} | A side cancelled; each side collects its own deposit. |
In the Dashboard
Section titled “In the Dashboard”- Activity: every
open,offer,pay,confirmandcancel, with its arguments and how it ended. - No page of its own: a trade has no catalog. A player card shows the inventory and the wallet the goods and the money pass through.
Limits
Section titled “Limits”- No invite and no notification: the other player learns of a trade out of band, and a trade opened against a player who does not exist can only be cancelled.
- No expiry and no timer: an abandoned trade keeps its deposits until someone cancels it.
- If a side’s inventory is full when it collects, the goods wait until there is room.
- The status of a trade is shown in code (
open,settled,cancelled); the Dashboard has no labels for these values yet.