> For the complete documentation index, see [llms.txt](https://docs.shyft.to/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shyft.to/solana/get-transactions-for-address/code-examples.md).

# Code Examples

### Fetching Transactions by Order

Traverse an address's full history forwards in time — something that wasn't possible with a single `getSignaturesForAddress` call.

#### Newest first (default)

Fetches the 100 most recent transactions for an address, starting from the latest and going backwards in time. This is the default behavior — useful when you want to see what happened most recently on a wallet.

{% tabs %}
{% tab title="JavaScript" %}
{% code overflow="wrap" %}

```javascript
const response = await fetch("https://rpc.shyft.to?api_key=YOUR_API_KEY", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getTransactionsForAddress",
    params: [
      "5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h", // base58 address to fetch transactions for
      {
        sortOrder: "desc", //sort order descending (default behavior)
        limit: 100
      }
    ]
  })
});

const { result } = await response.json();
result.data.forEach(tx => console.log(tx));
```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code overflow="wrap" %}

```rust
use reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() {
    let client = Client::new();

    let response = client
        .post("https://rpc.shyft.to?api_key=YOUR_API_KEY")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getTransactionsForAddress",
            "params": [
                "5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h",  // base58 address to fetch transactions for
                {
                    "sortOrder": "desc", //sort order descending (default behavior)
                    "limit": 100
                }
            ]
        }))
        .send()
        .await
        .unwrap()
        .json::<Value>()
        .await
        .unwrap();

    let transactions = response["result"]["data"].as_array().unwrap();
    for tx in transactions {
        println!("{:#?}", tx);
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Oldest First

Fetches transactions starting from the earliest recorded activity for the address and moves forward in time. Useful when you want to replay an address's history from the beginning - for example, reconstructing the full transaction timeline of a wallet, or fetching its first ever transaction.

{% hint style="success" %}
With sortOrder: "asc", you can fetch an **address's transactions starting from its very first - directly**, without having to paginate backwards through thousands of results first.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}
{% code overflow="wrap" %}

```javascript
const response = await fetch("https://rpc.shyft.to?api_key=YOUR_API_KEY", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getTransactionsForAddress",
    params: [
      "5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h", // base58 address to fetch transactions for
      {
        sortOrder: "asc", // order ascending: traverse history from the beginning
        limit: 100
      }
    ]
  })
});

const { result } = await response.json();
result.data.forEach(tx => console.log(tx));
```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code overflow="wrap" %}

```rust
use reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() {
    let client = Client::new();

    let response = client
        .post("https://rpc.shyft.to?api_key=YOUR_API_KEY")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getTransactionsForAddress",
            "params": [
                "5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h", // base58 address to fetch transactions for
                {
                    "sortOrder": "asc", // order ascending: traverse history from the beginning
                    "limit": 100
                }
            ]
        }))
        .send()
        .await
        .unwrap()
        .json::<Value>()
        .await
        .unwrap();

    let transactions = response["result"]["data"].as_array().unwrap();
    for tx in transactions {
        println!("{:#?}", tx);
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="danger" %}
Shyft RPC retains up to <mark style="color:yellow;">3-4 days</mark> of transaction history. With `sortOrder: "asc"`, you get the oldest transaction available in that window — not necessarily the genesis transaction for the address.
{% endhint %}

### Fetch token balance changes for an owner address

The `balanceChanged` filter tells the server to find all SPL token accounts owned by the queried owner address and return only the transactions where a token balance actually changed.

{% tabs %}
{% tab title="JavaScript" %}
{% code overflow="wrap" %}

```javascript
const response = await fetch("https://rpc.shyft.to?api_key=YOUR_API_KEY", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getTransactionsForAddress",
    params: [
      "DNfuF1L62WWyW3pNakVkyGGFzVVhj4Yr52jSmdTyeBHm", // add owner address(base58) for fetching transactions
      {
        filters: { tokenAccounts: "balanceChanged" } 
        // token account filter: include transactions that changed the balance of a token account owned by the owner address.
      }
    ]
  })
});

const { result } = await response.json();
result.data.forEach(tx => console.log(tx));
```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code overflow="wrap" %}

```rs
use reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() {
    let client = Client::new();

    let response = client
        .post("https://rpc.shyft.to?api_key=YOUR_API_KEY")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getTransactionsForAddress",
            "params": [
                "DNfuF1L62WWyW3pNakVkyGGFzVVhj4Yr52jSmdTyeBHm", // add owner address(base58) for fetching transactions
                { "filters": { "tokenAccounts": "balanceChanged" } } // include transactions that changed the balance of a token account owned by the owner address.
            ]
        }))
        .send()
        .await
        .unwrap()
        .json::<Value>()
        .await
        .unwrap();

    let transactions = response["result"]["data"].as_array().unwrap();
    for tx in transactions {
        println!("{:#?}", tx);
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Fetch transactions within a slot range

The `slot` filter tells the server to return only transactions confirmed within the given slot range.

{% tabs %}
{% tab title="JavaScript" %}
{% code overflow="wrap" %}

```javascript
const response = await fetch("https://rpc.shyft.to?api_key=YOUR_API_KEY", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getTransactionsForAddress",
    params: [
      "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", // base58 address for which txns will be fetched
      {
        filters: {
          slot: { gte: 332390000, lt: 332399000 } // slot range filter
        }
      }
    ]
  })
});

const { result } = await response.json();
result.data.forEach(tx => console.log(tx));
```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code overflow="wrap" %}

```rs
use reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() {
    let client = Client::new();

    let response = client
        .post("https://rpc.shyft.to?api_key=YOUR_API_KEY")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getTransactionsForAddress",
            "params": [
                "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P",  // base58 address for which txns will be fetched
                { "filters": { "slot": { "gte": 332390000, "lt": 332399000 } } } //slot range filter
            ]
        }))
        .send()
        .await
        .unwrap()
        .json::<Value>()
        .await
        .unwrap();

    let transactions = response["result"]["data"].as_array().unwrap();
    for tx in transactions {
        println!("{:#?}", tx);
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
Since slot production speed varies slightly (validator skips, network conditions), don't rely on these estimates for precision time-based queries. If you need exact time ranges, use `blockTime` with Unix timestamps instead — it's more reliable for wall-clock scoping. Use `slot` when you already have a known reference slot from a previous query or transaction.
{% endhint %}

### Fetch successful transactions only

The `status: "succeeded"` filter tells the server to return only transactions that executed successfully - where `meta.err` is `null`. Failed transactions are excluded from the results.

{% tabs %}
{% tab title="JavaScript" %}
{% code overflow="wrap" %}

```javascript
const response = await fetch("https://rpc.shyft.to?api_key=YOUR_API_KEY", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getTransactionsForAddress",
    params: [
      "TitanLozLMhczcwrioEguG2aAmiATAPXdYpBg3DbeKK", // base58 address for which the transactions will be fetched
      {
        filters: { status: "succeeded" }, //filtering transactions with status
        limit: 100
      }
    ]
  })
});

const { result } = await response.json();
result.data.forEach(tx => console.log(tx));
```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code overflow="wrap" %}

```rust
use reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() {
    let client = Client::new();

    let response = client
        .post("https://rpc.shyft.to?api_key=YOUR_API_KEY")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getTransactionsForAddress",
            "params": [
                "TitanLozLMhczcwrioEguG2aAmiATAPXdYpBg3DbeKK", // base58 address for which the transactions will be fetched
                { "filters": { "status": "succeeded" }, "limit": 100 } //filtering txns with status 
            ]
        }))
        .send()
        .await
        .unwrap()
        .json::<Value>()
        .await
        .unwrap();

    let transactions = response["result"]["data"].as_array().unwrap();
    for tx in transactions {
        println!("{:#?}", tx);
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Fetch full transaction payloads

Setting `transactionDetails: "full"` returns the complete transaction payload - instructions, accounts, pre/post balances, logs, and metadata.

{% tabs %}
{% tab title="JavaScript" %}
{% code overflow="wrap" %}

```javascript
const response = await fetch("https://rpc.shyft.to?api_key=YOUR_API_KEY", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    jsonrpc: "2.0",
    id: 1,
    method: "getTransactionsForAddress",
    params: [
      "HLnpSz9h2S4hiLQ43rnSD9XkcUThA7B8hQMKmDaiTLcC", //base58 address for which txns are being fetched
      {
        transactionDetails: "full",
        encoding: "jsonParsed",
        maxSupportedTransactionVersion: 0,
        limit: 25 // maximum 100 transactions can be fetched in full mode
      }
    ]
  })
});

const { result } = await response.json();
result.data.forEach(tx => console.log(tx));
```

{% endcode %}
{% endtab %}

{% tab title="Rust" %}
{% code overflow="wrap" %}

```rs
use reqwest::Client;
use serde_json::{json, Value};

#[tokio::main]
async fn main() {
    let client = Client::new();

    let response = client
        .post("https://rpc.shyft.to?api_key=YOUR_API_KEY")
        .json(&json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getTransactionsForAddress",
            "params": [
                "HLnpSz9h2S4hiLQ43rnSD9XkcUThA7B8hQMKmDaiTLcC", //base58 address for which txns are being fetched
                {
                    "transactionDetails": "full",
                    "encoding": "jsonParsed",
                    "maxSupportedTransactionVersion": 0,
                    "limit": 25 // maximum 100 transactions can be fetched in full mode
                }
            ]
        }))
        .send()
        .await
        .unwrap()
        .json::<Value>()
        .await
        .unwrap();

    let transactions = response["result"]["data"].as_array().unwrap();
    for tx in transactions {
        println!("{:#?}", tx);
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Common Filters for Reference

**`status`** : Filter by whether the transaction succeeded or failed on-chain. Use `succeeded` to exclude failed transactions, `failed` to inspect errors only, or `any` to return both. Maps directly to whether `meta.err` is null or not.

**`slot`** :  Scope your query to a block range. Useful when you know roughly when an event happened and want to avoid scanning the entire address history.

**`blockTime`** :  Same as `slot` but uses wall-clock Unix timestamps instead of slot numbers. Convenient when working with human-readable date ranges. Less reliable than `slot` for very old blocks where `blockTime` may be `null`.

**`tokenAccounts`** : Expand coverage to SPL token accounts owned by the queried address. Set to `balanceChanged` to include only transactions where a token balance actually changed - useful for transfer and swap history. Set to `all` to include any transaction that touched an owned token account regardless of balance change.

**`signature`** : Bound your query relative to a known transaction signature's ledger position. Rarely needed in practice - prefer `slot` for range scans and `paginationToken` for resuming pages.
