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

# Ondo Global Markets (RWA)

> Buy and sell tokenized stocks & ETFs on BSC, with cross-chain funding and async order tracking

This example demonstrates buying and selling Ondo Global Markets tokenized stocks & ETFs with the
Pods API. Market-share strategies live on **BSC** (`Ondo-<TICKER>-bsc`), but you can fund a buy
from — or receive a sell payout on — another EVM chain; Pods handles the bridge.

<Note>
  **Settlement is asynchronous.** The on-chain transaction submits the request in seconds; the order
  reaches `SUCCESS` only after Ondo fills it (minutes later). Track it via `GET /actions/{id}`.
</Note>

## Overview

This example covers:

* **Market status** — `GET /ondo/stocks/market-status`
* **Buy** (`action=request-lend`) — fund cross-chain from Base USDC
* **Sell** (`action=request-withdraw`) — redeem shares, receive USDC cross-chain
* **Async order tracking** — `GET /actions/{id}`
* **Optional limit / expiry** — `priceInUsd` (USD cents) and `expireAt` (Unix seconds) on Ondo BSC bytecode; cancel via `GET /actions/{id}/cancel?wallet=`

## Prerequisites

* Node.js 18+
* Pods API key
* Wallet with USDC to buy (or an open Ondo position to sell)

## Installation

```bash theme={null}
npm install axios viem
```

## Environment Variables

```bash theme={null}
PODS_API_KEY=your-api-key
PRIVATE_KEY=0x...
BSC_RPC_URL=https://bsc-dataseed.binance.org
BASE_RPC_URL=https://base-mainnet.g.alchemy.com/v2/your-key
```

## Step-by-Step Walkthrough

### 1. Check Market Status

```javascript theme={null}
import axios from 'axios'

const pods = axios.create({
  baseURL: 'https://api.pods.finance',
  headers: { 'x-api-key': process.env.PODS_API_KEY, 'Content-Type': 'application/json' }
})

const { data: market } = await pods.get('/ondo/stocks/market-status', {
  params: { symbol: 'NVDAon' }
})
console.log('Market open:', market.isOpen, market.marketStatus)
```

### 2. Buy (request-lend) — cross-chain funding

Fund the BSC position from Base USDC. `amount` is in the `fromTokenAddress` token's base units
(6 decimals for Base USDC; 18 for BSC USDC). The response returns origin-chain `bytecode` legs and
an Action `id`.

```javascript theme={null}
const { data: buyBytecode } = await pods.get('/strategies/Ondo-NVDA-bsc/bytecode', {
  params: {
    action: 'request-lend',
    wallet: walletAddress,
    amount: '10000000', // $10 in Base USDC (6 decimals)
    fromChainId: 8453,
    fromTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' // USDC on Base
  }
})

console.log('actionId:', buyBytecode.id)
console.log('cross-chain:', buyBytecode.crossChain.isCrossChain, buyBytecode.chainIdIn, '→', buyBytecode.chainIdOut)
```

To pin a client CoW limit (cents) and/or `validTo`, add `priceInUsd` and `expireAt`. They are
independent and only work on Ondo BSC. See [limit price, expiry, and cancel](/guides/ondoglobal-markets#limit-price-expiry-and-cancel).

```javascript theme={null}
const expireAt = Math.floor(Date.now() / 1000) + 3600
const { data: limitBuy } = await pods.get('/strategies/Ondo-NVDA-bsc/bytecode', {
  params: {
    action: 'request-lend',
    wallet: walletAddress,
    amount: '10000000',
    fromChainId: 8453,
    fromTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
    priceInUsd: 32000, // $320.00
    expireAt
  }
})
console.log('limit $', limitBuy.quote.clientLimitPriceUsd, 'vs spot', limitBuy.quote.spotPriceUsd)
```

### 3. Sell (request-withdraw) — cross-chain payout

Redeem market shares and receive USDC on Base. `amountInShares` is the share amount (18 decimals).

```javascript theme={null}
const { data: sellBytecode } = await pods.get('/strategies/Ondo-NVDA-bsc/bytecode', {
  params: {
    action: 'request-withdraw',
    wallet: walletAddress,
    amountInShares: '5000000000000000000', // 5 shares (18 decimals)
    toChainId: 8453,
    toTokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' // USDC on Base
  }
})
```

### 4. Execute the request (atomic batch on the origin chain)

<Warning>
  Batch all origin-chain `bytecode` legs into **one transaction**. See
  [Executing Bytecode](/getting-started/executing-bytecode).
</Warning>

```javascript theme={null}
import { http, createWalletClient, publicActions } from 'viem'
import { bsc, base } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
import { executeLegsViaEip7702 } from './eip7702-batch.js'

const CHAIN_BY_ID = { 56: bsc, 8453: base }
const RPC_BY_ID = { 56: process.env.BSC_RPC_URL, 8453: process.env.BASE_RPC_URL }

const account = privateKeyToAccount(process.env.PRIVATE_KEY)
const originChainId = Number(buyBytecode.chainIdIn)

const walletClient = createWalletClient({
  account,
  chain: CHAIN_BY_ID[originChainId],
  transport: http(RPC_BY_ID[originChainId])
}).extend(publicActions)

const receipt = await executeLegsViaEip7702(walletClient, buyBytecode.bytecode)
console.log('Request submitted in block:', receipt.blockNumber)
```

### 5. Track the async order fill

The on-chain tx only submits the request. Poll the Action `id` until the order reaches a terminal
state. For cross-chain, the bridge leg settles first, then the order.

```javascript theme={null}
async function waitForOrder (id) {
  const terminal = ['SUCCESS', 'FAILED', 'REFUNDED', 'EXPIRED']
  while (true) {
    const { data: action } = await pods.get(`/actions/${id}`)
    console.log('Order status:', action.status)
    if (terminal.includes(action.status)) return action.status
    await new Promise(resolve => setTimeout(resolve, 10000))
  }
}

await waitForOrder(buyBytecode.id)
```

An unfilled **client-limit** order (`priceInUsd` set) can be cancelled after funding:

```javascript theme={null}
const { data: cancelled } = await pods.get(`/actions/${limitBuy.id}/cancel`, {
  params: { wallet: walletAddress }
})
console.log('cancelled status:', cancelled.status)
```

<Tip>
  For a strategy-scoped view of pending orders, use `GET /strategies/{id}/status?wallet={address}` —
  it returns `hasPending`, per-action `orderBook` eligibility, and the `actions[]` list.
</Tip>

## Running the Example

<Info>
  **Download both files into the same folder** to run this example:
  [`ondo.js`](/examples/javascript/ondo.js) and the shared EIP-7702 batch helper
  [`eip7702-batch.js`](/examples/javascript/eip7702-batch.js) that it imports.
</Info>

```bash theme={null}
node ondo.js market    # or: buy | sell
```

See the full runnable script: [`ondo.js`](/examples/javascript/ondo.js).

## Next Steps

<CardGroup cols={2}>
  <Card title="Ondo Global Markets Guide" icon="chart-line" href="/guides/ondoglobal-markets">
    Full buy/sell, cross-chain, and accounting details
  </Card>

  <Card title="Track & Positions" icon="magnifying-glass-chart" href="/examples/javascript/track-and-positions">
    Read positions and track actions
  </Card>

  <Card title="Cross-Chain Swap" icon="bridge" href="/examples/javascript/cross-chain-swap">
    Bridge tokens across chains
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/introduction">
    View complete API documentation
  </Card>
</CardGroup>
