> ## Documentation Index
> Fetch the complete documentation index at: https://core.vanish.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# Trade

> Get a private trade executing on Solana in under 30 minutes.

Continues from [Setup](https://core.vanish.trade/guide/quickstart/setup.md), using the `vanish`, `signMessage`, `broadcast`, and `commit` helpers defined there, and the balance you funded at the end of it.

***

## Execute a Trade

Vanish wraps your swap instructions - it does not build the route itself. Fetch an unsigned transaction from your DEX aggregator of choice and pass it to [`POST /trade/create`](https://core.vanish.trade/api-reference/trade/create).

> [!NOTE]
>
> **Critical:** set the **one-time wallet** as the transaction signer - not the user's wallet. Pass it wherever your aggregator asks for the signing wallet or user public key.

**1. Get a one-time wallet and build the swap**

```typescript TypeScript theme={null}
const SOL_MINT    = '11111111111111111111111111111111';
const TARGET_MINT = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'; // USDC
const AMOUNT      = '100000000'; // 0.1 SOL in lamports

// never reuse a one-time wallet - fetch a fresh one for every trade
const { address: oneTimeWallet } = await vanish('/trade/one-time-wallet');

const quote = await (await fetch(
  `https://quote-api.jup.ag/v6/quote?inputMint=${SOL_MINT}` +
  `&outputMint=${TARGET_MINT}&amount=${AMOUNT}&slippageBps=50`
)).json();

const { swapTransaction } = await (await fetch('https://quote-api.jup.ag/v6/swap', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    quoteResponse:    quote,
    userPublicKey:    oneTimeWallet,   // must be the one-time wallet
    wrapAndUnwrapSol: true,
    dynamicComputeUnitLimit: true,
  }),
})).json();
```

```rust Rust theme={null}
const SOL_MINT: &str    = "11111111111111111111111111111111";
const TARGET_MINT: &str = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"; // USDC
const AMOUNT: &str      = "100000000"; // 0.1 SOL in lamports

// never reuse a one-time wallet - fetch a fresh one for every trade
let otw = vanish(client, api_key, "/trade/one-time-wallet", None).await?;
let one_time_wallet = otw["address"].as_str().unwrap();

let quote: Value = reqwest::get(&format!(
    "https://quote-api.jup.ag/v6/quote?inputMint={SOL_MINT}\
     &outputMint={TARGET_MINT}&amount={AMOUNT}&slippageBps=50"
)).await?.json().await?;

let swap_res: Value = client
    .post("https://quote-api.jup.ag/v6/swap")
    .json(&serde_json::json!({
        "quoteResponse":           quote,
        "userPublicKey":           one_time_wallet,  // must be the one-time wallet
        "wrapAndUnwrapSol":        true,
        "dynamicComputeUnitLimit": true,
    }))
    .send().await?.json().await?;

let swap_transaction = swap_res["swapTransaction"].as_str().unwrap();
```

Jupiter is an example - any aggregator works, as long as it returns an unsigned transaction with the one-time wallet as signer.

**2. Create the trade and commit**

```typescript TypeScript theme={null}
const LOAN_SOL = '12000000'; // covers ATA creation - unused amount is refunded
const JITO_TIP = '1000000';  // 0.001 SOL - minimum recommended tip

const timestamp = Date.now().toString();

const trade = await vanish('/trade/create', {
  method: 'POST',
  body: JSON.stringify({
    user_address:         userKeypair.publicKey.toBase58(),
    source_token_address: SOL_MINT,
    target_token_address: TARGET_MINT,
    amount:               AMOUNT,
    swap_transaction:     swapTransaction,  // base64-encoded unsigned tx
    one_time_wallet:      oneTimeWallet,
    loan_additional_sol:  LOAN_SOL,
    jito_tip_amount:      JITO_TIP,
    split_repay:          1,
    timestamp,
    user_signature: signMessage(
      `trade:${SOL_MINT}:${TARGET_MINT}:${AMOUNT}:${LOAN_SOL}:${timestamp}:${JITO_TIP}`,
      userKeypair
    ),
    // omit prefer_non_jito to route via Jito (default)
  }),
});

// on the Jito route trade.transaction is null and broadcast() is a no-op
const txId = (await broadcast(trade)) ?? trade.tx_id;
const result = await commit('/commit', txId);

console.log('Status:', result.status, 'Changes:', result.balance_changes);
```

```rust Rust theme={null}
const LOAN_SOL: &str = "12000000"; // covers ATA creation - unused amount is refunded
const JITO_TIP: &str = "1000000";  // 0.001 SOL - minimum recommended tip

let timestamp = chrono::Utc::now().timestamp_millis().to_string();

let trade = vanish(client, api_key, "/trade/create", Some(&serde_json::json!({
    "user_address":         user_keypair.pubkey().to_string(),
    "source_token_address": SOL_MINT,
    "target_token_address": TARGET_MINT,
    "amount":               AMOUNT,
    "swap_transaction":     swap_transaction,  // base64-encoded unsigned tx
    "one_time_wallet":      one_time_wallet,
    "loan_additional_sol":  LOAN_SOL,
    "jito_tip_amount":      JITO_TIP,
    "split_repay":          1,
    "timestamp":            &timestamp,
    "user_signature": sign_message(
        &format!("trade:{SOL_MINT}:{TARGET_MINT}:{AMOUNT}:{LOAN_SOL}:{timestamp}:{JITO_TIP}"),
        &user_keypair,
    ),
    // omit prefer_non_jito to route via Jito (default)
}))).await?;

// on the Jito route trade["transaction"] is null and broadcast() is a no-op
let tx_id = broadcast(&rpc, &trade).await?
    .unwrap_or_else(|| trade["tx_id"].as_str().unwrap().to_string());
let result = commit(client, api_key, "/commit", &tx_id).await?;

println!("Status: {} Changes: {}", result["status"], result["balance_changes"]);
```

> [!WARNING]
>
> `/commit` must be called for every transaction - success, failure, or expiry. Check [`/account/pending`](https://core.vanish.trade/api-reference/account/get_pending_actions) whenever a user loads their account, so nothing is left uncommitted.

Adding `prefer_non_jito` makes Vanish hand back a signed transaction instead of submitting one itself. You broadcast it, and the signature your RPC returns is what you commit - not `trade.tx_id`. See [Routing Options](https://core.vanish.trade/guide/integration/trading.md#routing-options).

***

## Check Balances

Sign `read:{timestamp}` and send it as `signature`. The same signature is accepted for 24 hours, so you can reuse it across polls. See [`POST /account/balances`](https://core.vanish.trade/api-reference/account/get_balances) for the full reference.

```typescript TypeScript theme={null}
const timestamp = Date.now().toString();

const balances = await vanish('/account/balances', {
  method: 'POST',
  body: JSON.stringify({
    user_address: userKeypair.publicKey.toBase58(),
    timestamp,
    signature: signMessage(`read:${timestamp}`, userKeypair),
  }),
});

// [{ token_address, balance, program_id }, ...]
// balance is in lamports for SOL, base units for SPL tokens
console.log(balances);
```

```rust Rust theme={null}
let timestamp = chrono::Utc::now().timestamp_millis().to_string();

let balances = vanish(client, api_key, "/account/balances", Some(&serde_json::json!({
    "user_address": user_keypair.pubkey().to_string(),
    "timestamp":    &timestamp,
    "signature":    sign_message(&format!("read:{timestamp}"), &user_keypair),
}))).await?;

// [{ token_address, balance, program_id }, ...]
println!("{}", balances);
```

***

## Next Steps

* [Lend](https://core.vanish.trade/guide/quickstart/lend.md) - Open a position against the same funded balance, then settle it.
* [Trading](https://core.vanish.trade/guide/integration/trading.md) - The full reference for the trade flow, including routing guidance.
* [Error Handling](https://core.vanish.trade/guide/handling.md) - Commit statuses and recovering interrupted flows.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.