<TradingAgentSetup />

```js
import bs58 from "bs58";
import nacl from "tweetnacl";
const API = "https://api.gum.ag/app/v1";
const secretKey = bs58.decode(process.env.SOLANA_SECRET_KEY);
const address = bs58.encode(secretKey.slice(32));
const call = async (path, body) => {
  const res = await fetch(API + path, {
    method: body ? "POST" : "GET",
    headers: { "content-type": "application/json" },
    body: body && JSON.stringify(body),
  });
  const data = await res.json();
  if (!res.ok) throw new Error(`${data.error.code}: ${data.error.message}`);
  return data;
};
```

## 1. Quote

```js
const quote = await call("/swap/quote", {
  address,
  side: "buy",
  chainId: 900,
  token: "So11111111111111111111111111111111111111112",
  amount: "5",
});
```

To sell, set `side: "sell"` and give `amount` in tokens.

## 2. Sign

```js
const message = Uint8Array.from(atob(quote.message), (c) => c.charCodeAt(0));
const signature = bs58.encode(nacl.sign.detached(message, secretKey));
```

With an EVM wallet, pass your `0x` address and sign with `personal_sign`, e.g.
viem's `account.signMessage({ message: { raw: message } })`. See
[Sign with your wallet](/trading-api/signing).

## 3. Submit

```js
const { id } = await call("/swap", {
  transaction: quote.transaction,
  signature,
});
```

## 4. Track

```js
let trade;
do {
  await new Promise((resolve) => setTimeout(resolve, 2000));
  trade = await call(`/swap/${id}`);
} while (!trade.final);
```

Or stream `/v1/swap/{id}/events`. See [Track status](/trading-api/status).
