Start
Quickstart
Place a first order, watch its batch clear, and open the batch it filled in.
This page takes a wallet from nothing to a filled order, once in the app and once in a script. It needs a Solana wallet that holds the token to sell, and SOL for the transaction fee and the order account's rent.
In the app
Connect
Open
/tradeand press Connect wallet to trade. The form shows the wallet's balance of the token in the Sell field.Fill the form
Enter the amount under Sell and choose the two tokens. Limit is the least the order accepts, in the buy token per one of the sell token. It is prefilled from the last proven price, and You receive at least shows what that limit means for this amount. An order has to be worth at least 0.0001 SOL at the sell token's last proven price, and the form says so under a smaller amount.
Place order
Press Place order and sign in the wallet. The button reads Preparing, Sign in your wallet, then Sent. Confirming. When the notice reads Confirmed, the sell amount has moved to the token's vault and the order is in the open batch.
Watch the window
The strip above the form shows the open batch and the orders in it. While the batch has no orders it reads Window Starts with the next order. With an order in it, it reads Closes in and counts down the batch window, 10 slots, 2 seconds. Under Your orders the order's status is In window, with Cancel beside it.
See the fill
The batch seals and a solver clears it. Received shows what the order bought and the status reads Filled. The keeper then settles the order: the status reads Settled and the bought tokens are in the wallet.
Open the batch
The number in the order's Batch column leads to
/batches/[id]. That page shows the cleared price of each token, the solver and its bond, the input hash, the proof transaction once it lands, and your orders in the batch with what they received.
In a script
Install the SDK, and @solana/web3.js to load the keypair:
npm install @una/sdk @solana/web3.jscreateUna binds the API to a wallet. Every write call on it builds the transaction, signs it with the wallet, sends it and waits for it to confirm.
import { readFileSync } from 'node:fs'
import { createUna } from '@una/sdk'
import { Keypair } from '@solana/web3.js'
// A wallet: a Solana keypair file. The SDK signs with it; the key never leaves this process.
const wallet = Keypair.fromSecretKey(new Uint8Array(JSON.parse(readFileSync(process.env.KEYPAIR!, 'utf8'))))
const una = createUna({ apiUrl: 'https://api.una.markets', wallet })Then one call places the order. This one sells 0.5 SOL for USDC at the limit the API suggests from the last proven prices:
const { items: tokens } = await una.tokens()
const sol = tokens.find((t) => t.symbol === 'SOL')!
const usdc = tokens.find((t) => t.symbol === 'USDC')!
const amount = 500_000_000n // lamports
const quote = await una.quote({ sellMint: sol.mint, buyMint: usdc.mint, amount: amount.toString() })
const placed = await una.swap({
sell: sol.mint,
buy: usdc.mint,
amount: amount.toString(),
limit: quote.suggestedLimitQ64,
})
console.log(`order ${placed.orderAddress} placed, transaction ${placed.signature}`)amount is in atoms of the sell token and limit is a Q64.64 integer, both as decimal strings. una.swap resolves once the transaction has confirmed, with the order's address, the transaction's signature and the order as the API has it.
Wait for the order's batch to clear, then read the order:
// The order's own batch, once the API has the order. Until then, the batch the transaction was built for.
const batchId = placed.order?.batchId ?? placed.batchId
let batch = await una.batch(batchId)
while (batch.status === 'open' || batch.status === 'sealed') {
await new Promise((r) => setTimeout(r, 400))
batch = await una.batch(batchId)
}
const order = await una.order(placed.orderAddress)
console.log(`order is ${order.status}: sold ${order.filledAmount}, received ${order.receivedAmount}, fee ${order.feeAmount}`)una.order returns an Order: filledAmount is what it sold, receivedAmount what it bought and feeAmount the clearing fee, each in atoms. una.batch returns a BatchDetail with the cleared prices and the bond locked behind them.
Run it with the path of a keypair file:
KEYPAIR=~/.config/solana/id.json node --experimental-strip-types order.tsThe SDK quickstart has the full script, with the limit set by hand, the errors a call can raise, and reading without a wallet.