DEV Community

TateLyman
TateLyman

Posted on

Build a Copy Trading Bot for Solana — Watch Any Wallet, Mirror Their Trades

How Copy Trading Works

Copy trading monitors a target wallet and automatically mirrors their trades. When they buy a token, you buy it. When they sell, you sell.

Implementation

1. Watch Wallet Transactions

const { Connection } = require('@solana/web3.js');

async function pollWallet(walletAddress, lastSig) {
  const conn = new Connection('https://api.mainnet-beta.solana.com');
  const sigs = await conn.getSignaturesForAddress(
    new PublicKey(walletAddress),
    { until: lastSig, limit: 10 }
  );
  return sigs;
}
Enter fullscreen mode Exit fullscreen mode

2. Detect Token Swaps

Parse each transaction to find Jupiter/Raydium swap instructions:

function isSwap(tx) {
  const jupiterProgram = 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4';
  return tx.transaction.message.accountKeys.some(
    key => key.toString() === jupiterProgram
  );
}
Enter fullscreen mode Exit fullscreen mode

3. Extract Token Details

From the swap instruction, extract which token was bought/sold and the amount.

4. Mirror the Trade

Execute the same swap with your configured amount.

Polling Interval

I poll every 60 seconds. Fast enough to catch most moves, slow enough to avoid RPC rate limits.

In My Bot

/copy <wallet_address>   — start copying
/copy list               — see active copy trades
/copy stop               — stop all
Enter fullscreen mode Exit fullscreen mode

Free bot: @solscanitbot

Full source: devtools-site-delta.vercel.app/sol-bot-source

Top comments (0)