#testnet channel; the trading contracts on Sepolia are the same as mainnet.
1
Install the SDK
2
Create an agent key
The agent is a fresh EVM key that signs API requests and broadcasts the transactions the API prepares, so it needs a little ETH for gas. It never holds collateral. Keep it in an environment variable or a secret manager, never in source.
3
Authorise the agent with the master wallet
Two things happen: the API records the agent and its scope (signed by the master wallet), and the master wallet sends one on-chain transaction, Once the transaction is mined,
setTradingDelegate(agent), which names the agent as the trader’s delegate. The API returns that transaction ready to send. The client is built with a sender: the agent’s wallet client, which will sign and broadcast every prepared transaction.client.agents.get(agent.address) reports status: "active". The delegation is per trader and per chain, and removeTradingDelegate cuts it. A trader who wants to sign with its own wallet registers itself as agent: no delegation, delegationTx is null.4
Approve USDC once
The trader’s collateral stays in the trader’s wallet. The Diamond pulls it when an order opens, so the master wallet must approve the Diamond for USDC once (any amount,
maxUint256 is common). GET /v1/{chain} returns the Diamond address (diamond) and GET /v1/{chain}/markets the USDC token address (collaterals[].address); both are also in the contracts reference.5
Place a market order and wait for the fill
size is in base asset (here BTC). The API derives the USDC collateral from size × price / leverage, simulates the order from the agent and returns the transaction; orders.create signs and broadcasts it with the sender, reports the hash (POST /orders/{id}/submit) and returns the pending order. waitForFill polls GET /orders/{id} and throws OrderNotFilledError on rejected, timed_out, canceled or expired, so an unfilled order never looks like a filled one.6
Read the position, then close it
The same flow in plain HTTP
Every private request carries four headers. The signature is EIP-712 over the request itself; see Authentication for the exact struct.BTC-USD (or URL-encoded BTC%2FUSD); in JSON bodies they are BTC/USD.
The write above answers 201 with { order, transaction }. Sign and broadcast transaction with the agent key (eth_sendTransaction with to, data, value: "0"), then report the hash:
Next
- Authentication: scopes, revocation, read-only keys, the signature spec.
- Orders and positions: limit and stop orders, partial closes, SL/TP, leverage changes.
- WebSocket: stream prices, the book and your order updates instead of polling.
