{"id":18794414,"url":"https://github.com/chainstacklabs/raydium-sdk-swap-example-typescript","last_synced_at":"2026-01-19T12:01:23.583Z","repository":{"id":225910370,"uuid":"767217750","full_name":"chainstacklabs/raydium-sdk-swap-example-typescript","owner":"chainstacklabs","description":"An example to swap tokens on Solana using the Raydium SDK, TypeScript, and Chainstack","archived":false,"fork":false,"pushed_at":"2025-01-07T04:09:46.000Z","size":108,"stargazers_count":175,"open_issues_count":7,"forks_count":46,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-04T09:42:30.585Z","etag":null,"topics":["chainstack","raydium","solana","swap","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chainstacklabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-04T22:45:00.000Z","updated_at":"2025-03-25T13:35:10.000Z","dependencies_parsed_at":"2024-03-08T18:25:57.642Z","dependency_job_id":"6f954e41-c8b4-46a2-9abc-a01edae9ca27","html_url":"https://github.com/chainstacklabs/raydium-sdk-swap-example-typescript","commit_stats":null,"previous_names":["soos3d/raydium-sdk-swap-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chainstacklabs/raydium-sdk-swap-example-typescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainstacklabs%2Fraydium-sdk-swap-example-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainstacklabs%2Fraydium-sdk-swap-example-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainstacklabs%2Fraydium-sdk-swap-example-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainstacklabs%2Fraydium-sdk-swap-example-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chainstacklabs","download_url":"https://codeload.github.com/chainstacklabs/raydium-sdk-swap-example-typescript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainstacklabs%2Fraydium-sdk-swap-example-typescript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28567861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T08:53:44.001Z","status":"ssl_error","status_checked_at":"2026-01-19T08:52:40.245Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chainstack","raydium","solana","swap","typescript"],"created_at":"2024-11-07T21:29:24.094Z","updated_at":"2026-01-19T12:01:23.566Z","avatar_url":"https://github.com/chainstacklabs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"**\u003e\u003eWARNNING ON SCAMS IN ISSUES COMMENT SECTION\u003c\u003c**\n\nThe issues comment section is often targeted by scam bots willing to redirect you to an external resource and drain your funds.\n\nI have enabled a GitHub actions script to detect the common patterns and tag them, which obviously is not 100% accurate.\n\nThe official maintainers are in the [MAINTAINERS.md](MAINTAINERS.md) file.\n\nNot everyone is a scammer though, sometimes there are helpful outside devs who comment and I absolutely appreciate it.\n\n**\u003e\u003eEND OF WARNING\u003c\u003c**\n\n# TLDR quick run\n\nDownload the latest Raydium mainnet.json to the project root (it's a ~500 MB file):\n\n```\nwget https://api.raydium.io/v2/sdk/liquidity/mainnet.json\n```\n\nSet the tokenA and tokenB in `src/swapConfig.ts`.\n\nNow that you have the the 500 MB `mainnet.json` that has the entrirety of info on liquidity pairs, and you have the correct pairs set in `swapConfig.ts`, you want to trim the `mainnet.json` file to have only the necessary liquidity info pertaining to your tokenA \u0026 tokenB. So run:\n\n```\nts-node src/trimMainnet.ts\n```\n\nThis will produce `src/trimmed_mainnet.json` that takes less than a second to load vs minutes for `mainnet.json`.\n\nMake sure you have the Chainstack node \u0026 your private key set in `.env`. Make sure you have all dependencies installed with `yarn`.\n\nRun the swap:\n\n```\nyarn swap\n```\n# Raydium SDK Swap Example\n\nThis project demonstrates how to perform a token swap on the Solana blockchain using Raydium and Chainstack. The example specifically illustrates swapping SOL (native Solana token) for USDC (a stablecoin).\n\nFind the full [guide on the Chainstack Developer Portal](https://docs.chainstack.com/docs/solana-how-to-perform-token-swaps-using-the-raydium-sdk).\n\n\u003e Shoutout to [precious-void](https://github.com/precious-void) for the the [base code](https://github.com/precious-void/raydium-swap) used for this project!\n\n## Features\n\n- Utilizes the Raydium SDK for interacting with the Solana blockchain.\n- Supports both versioned and legacy transactions.\n- Allows simulation of swap transactions before execution.\n- Easy configuration for swap parameters through a dedicated config file.\n\n## Prerequisites\n\nBefore you begin, ensure you have met the following requirements:\n\n- Node.js installed (v18 or above recommended)\n- Yarn\n- A Solana wallet with some SOL for testing the swap\n- An environment file (.env) with your RPC URL and WALLET_PRIVATE_KEY\n\n## Chainstack Solana node\n\nDeploy a Solana node on Chainstack; the following steps will guide you:\n\n1. [Sign up with Chainstack](https://console.chainstack.com/user/account/create).\n2. [Deploy a node](https://docs.chainstack.com/docs/manage-your-networks#join-a-public-network).\n3. [View node access and credentials](https://docs.chainstack.com/docs/manage-your-node#view-node-access-and-credentials).\n\n## Environment variables\n\nAdd your RPC endoint and private key to a `.env` file:\n\n```env\nRPC_URL=YOUR_RPC_URL\nWALLET_PRIVATE_KEY=YOUR_PRIVATE_KEY\n```\n\n## Installation\n\nClone the repository locally and install the dependencies:\n\n```bash\ngit clone https://github.com/soos3d/raydium-sdk-swap-example.git\ncd raydium-sdk-swap-example\nyarn\n```\n\n## Usage\n\nEdit the configuration in `src/swapConfig.ts` editing:\n\n- Select if you want to send the transaction or only simulate\n- The amount to swap\n- The tokens to swap\n- The liquidity file to pull the pool info from\n\n```ts\nexport const swapConfig = {\n  executeSwap: false, // Send tx when true, simulate tx when false\n  useVersionedTransaction: true,\n  tokenAAmount: 0.01, // Swap 0.01 SOL for USDT in this example\n  tokenAAddress: \"So11111111111111111111111111111111111111112\", // Token to swap for the other, SOL in this case\n  tokenBAddress: \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\", // USDC address\n  maxLamports: 1000000, // Max lamports allowed for fees\n  direction: \"in\" as \"in\" | \"out\", // Swap direction: 'in' or 'out'\n  liquidityFile: \"https://api.raydium.io/v2/sdk/liquidity/mainnet.json\",\n  maxRetries: 10\n};\n```\n\nThen run:\n\n```sh\nyarn swap\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainstacklabs%2Fraydium-sdk-swap-example-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchainstacklabs%2Fraydium-sdk-swap-example-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainstacklabs%2Fraydium-sdk-swap-example-typescript/lists"}