Raydium is a decentralized order book and automated market maker (AMM) platform built on the Solana blockchain. While the Raydium frontend provides a user-friendly interface for swapping tokens, not all users interact with the platform through this interface. Developers, in particular, may need to build applications or server-side scripts that interact directly with the Raydium smart contracts to facilitate token swaps or leverage other Raydium features.
In this script, I’ll provide a code example that demonstrates how to build a script for swapping tokens on the Raydium AMM using TypeScript.
- Run this command to set environment variables
cp .env.example .env - Set
CREATOR_PRIVATE_KEYwith uint8Array keypair - Set
BURNER_WALLETwith the public address of the destination wallet. - Set
TOKEN_MINT_ADDRESSwith the target SPL token address - Set
POOL_IDwith the SOL/TOKEN pool id - Set
GIREUMEE_POOL_IDwith the SOL/GIREUMEE pool id - Set
RPC_CLUSTERwith proper networkmainnet-betadevnet
- Set
THRESHOLD_AMOUNTwith the threshold amount to trigger swap function. - Set
INTERVAL_PERIODwith the period of monitoring loop10000=> 10 seconds
After setting up proper configurations run this script.
npm install
npm run swap