Canonical: https://nitride.xyz/use-cases/copy-trading

# Copy trading from shreds

How a Solana copy trading bot uses raw shreds: signer matching without lookup tables, what a swap reveals early, failed trades, and when Ultra beats Standard.

Copy trading from shreds means watching a list of wallets in Solana's raw block stream and reacting to their swaps while the leader is still broadcasting the block, instead of waiting for RPC to report a confirmed transaction. Your bot still trades after the wallet it copies, so sizing, slippage limits and execution decide the result.

## How does a copy trading bot work on Solana?
A copy trading bot has four steps: pick the wallets to follow, detect their trades, translate each trade into your own (same token and side, scaled size, a price limit), and send it. RPC is the usual starting point for detection, for example a `logsSubscribe` stream that reports transactions mentioning an address once they are processed or confirmed.

Shreds replace that detection step. You see the watched wallet's transaction inside the leader's block as it is broadcast. The other three steps are unchanged, and they are where most of the result comes from.

Be clear about one structural fact: you are always behind the wallet you copy. Its trade is already in a block when you see it. On a deep pool that barely matters. On a thin bonding curve, the copied wallet's buy moves the price, every other follower of the same wallet moves it again, and you pay for both. Detection speed narrows that gap; it never closes it.

Copy trading often starts from launches, since many followed wallets trade new tokens. [Token launch detection](https://nitride.xyz/use-cases/token-launch-detection) covers that side, and [trading alerts built on shreds](https://nitride.xyz/use-cases/trading-alerts) covers bots that notify a person instead of trading.

## What do shreds reveal about a watched wallet?
- **Who signed, with no lookups.** Every signer of a transaction is one of its static account keys, and the fee payer is always the first. A version 0 transaction can pull other accounts from lookup tables, but never its signers. Matching a watched wallet is a scan of the first few keys.
- **Which venue and which arguments.** The swap instruction names the program (an AMM, a launchpad or an aggregator router) and carries its arguments, usually an input amount and a minimum output. The minimum output bounds the price the wallet accepted, which helps you set your own limit. Aggregator routes are harder to read and need a parser per router.
- **Which tokens.** Mints and pool accounts may come through lookup tables. Resolving them needs your own copy of those tables.
- **Who else reacted.** Transactions later in the same block show whether other copiers already followed the trade, and roughly how many.

Shreds do not show the fill. The amount the wallet actually received is in the execution metadata, as are its balance changes and whether the swap succeeded at all.

## Ultra or Standard for copy trading?
The answer follows the market you copy into.

For new tokens on bonding curves and other thin pools, choose Ultra Low Latency Shreds. For $200 per destination per 30 days, shreds come straight from our server with no relay hop, ahead of Standard. Each follower ahead of you pays a better price, so every bit of detection time shows up in your fills.

For swaps in deep pools, or wallets that hold positions for hours or days, Standard Shreds is enough. It costs $100 for one destination for 30 days, delivered through our relay. The price a few slots later barely differs, and your edge comes from choosing wallets well. The contents of both plans are identical.

If many bots follow the same wallet, detection on its own is shared; sizing, slippage and how you land transactions separate the results. We publish no latency figure. Compare the arrival of a watched wallet's swap in shreds with your RPC notification for the same signature, on your own server, then decide. [Ultra Low Latency vs Standard Shreds](https://nitride.xyz/compare/ultra-vs-standard-shreds) sets out the difference in full.

## A receiver sketch in Rust
The receive thread copies each datagram into a bounded queue and drops it, with a log line, if the queue is full. A second thread buckets packets by slot (a little-endian u64 at offset 65, 8 bytes), decodes a slot once a newer one starts, and checks the signers of each transaction against your list. `decode_slot` is your code or an open-source shred decoder.

```rust file="copy_watch.rs"
use std::collections::{HashMap, HashSet};
use std::net::UdpSocket;
use std::sync::mpsc;
use std::thread;

/// Filled by your decoder from each transaction's message.
struct Tx {
    signatures: Vec<[u8; 64]>,
    static_keys: Vec<[u8; 32]>,
    num_signers: usize, // message header: num_required_signatures
}

fn decode_slot(_shreds: &[Vec<u8>]) -> Vec<Tx> {
    unimplemented!("FEC recovery, entry deserialisation, transactions")
}

fn watched_signer(tx: &Tx, watched: &HashSet<[u8; 32]>) -> Option<[u8; 32]> {
    tx.static_keys.iter().take(tx.num_signers).find(|k| watched.contains(*k)).copied()
}

fn main() -> std::io::Result<()> {
    let watched: HashSet<[u8; 32]> = HashSet::new(); // load the wallets you follow
    let socket = UdpSocket::bind("0.0.0.0:9000")?;
    let (queue, packets) = mpsc::sync_channel::<Vec<u8>>(65_536);

    thread::spawn(move || {
        let mut by_slot: HashMap<u64, Vec<Vec<u8>>> = HashMap::new();
        let mut copied: HashSet<[u8; 64]> = HashSet::new();
        let mut newest = 0u64;
        for pkt in packets {
            let slot = u64::from_le_bytes(pkt[65..73].try_into().unwrap());
            by_slot.entry(slot).or_default().push(pkt);
            if slot <= newest { continue; }
            newest = slot;
            let ready: Vec<u64> = by_slot.keys().copied().filter(|s| *s < newest).collect();
            for s in ready {
                for tx in decode_slot(&by_slot.remove(&s).unwrap()) {
                    let Some(wallet) = watched_signer(&tx, &watched) else { continue };
                    if copied.insert(tx.signatures[0]) {
                        // size it, set a price limit, send through your own path
                        println!("slot {s}: followed wallet {:02x?} traded", &wallet[..4]);
                    }
                }
            }
        }
    });

    let mut buf = [0u8; 1228];
    loop {
        let (len, _peer) = socket.recv_from(&mut buf)?;
        if len >= 83 && queue.try_send(buf[..len].to_vec()).is_err() {
            eprintln!("decoder queue full: packet dropped");
        }
    }
}
```

The `copied` set keys on the transaction's first signature. Late shreds can reopen a slot that was already decoded, and the same transaction would otherwise trigger twice. In production, cap that set by slot age. Waiting for the next slot before decoding is the simple choice; a faster bot decodes each FEC set the moment it is complete.

The [Rust receiver page](https://nitride.xyz/docs/rust) has the full header table and a source-address check you should add once delivery is active.

## What are the limits of copying from shreds?
- **You may copy a trade that failed.** Shreds include transactions that run out of slippage or error out. Acting on the shred risks following a trade that never happened; waiting for confirmation is safer and slower. Choose per strategy.
- **Skipped slots and forks.** A block that never confirms takes the wallet's trade with it.
- **Lost packets hide trades.** Raw UDP has no retransmission. Track slots your decoder could not rebuild, and keep an RPC listener as a second path so a missed trade is at least noticed.
- **You decode everything,** including every router format you care about.
- **One city.** Your copy bot sits closest to the action when its server is near Frankfurt.

## Next steps
[What a shred is](https://nitride.xyz/blog/what-is-a-shred) explains why the wallet's transaction is visible this early, and [where Solana latency comes from](https://nitride.xyz/learn/solana-latency) breaks down the rest of the delay between their trade and yours. If you also quote the tokens you follow, see [shreds for Solana market makers](https://nitride.xyz/use-cases/market-making). The [use cases hub](https://nitride.xyz/use-cases) covers the remaining workloads.

### Do I need to resolve lookup tables to match a wallet?

Not for the signer. Signers are always static keys, with the fee payer first. You do need table contents to name the mints and pools a swap touches when it loads them from a lookup table.

### Will shreds put my copy trade ahead of the wallet I follow?

No. Its transaction is already in the leader's block when you see it. Shreds shorten the time until you know, so you trade nearer to its price.

### What if the copied wallet's transaction fails?

Shreds cannot tell you. Either accept the risk of copying a failed trade, or wait for its confirmed status before acting and give up time.
