I'm currently on a project that makes me need to do a swap transaction between SOL and a specific token (specifying the token's address) through raydium, and we are using python to build this interface. Would it be possible to perform this swap operation using Python code? Do you have any example code, SDK or lib available for this?

  • I am also trying to make swap in python and js web3 node and rust Commented Jan 31 at 22:30

1 Answer 1


Basic Steps:

  1. Import pool keys from here.
  2. Create instruction with imported pool keys and get Associated token accounts or the token account or create a wrapped solana account.
  3. Create close WSOL acocunt instructions
  4. Create a transaction e.g. txn = Transaction()
  5. Pass the instructions
  6. Sign the txn
  7. SendTransaction and confirm

More information about the swap can be found in raydium sdk which is in Typescript or you can read through my code for raydium swap but its not well organized or so called clean code.

Main issues with raydium swap from my experience, if you are trying to retrieve pool keys simultaneously in multiple threads for multiple coins, the api.raydium.io will rate limit you and it takes long time to get the keys due to which transaction execution time is to infinity and beyond.

  • Thanks friend! I will try your code! I noticed you are building a sniping bot, that looks interesting. Do you have any means of contact like Telegram that you can share? I'm also a programmer and I have some good contacts, I believe we can think about some degen things together Commented Dec 28, 2023 at 12:57
  • check my profiles :)
    – kokiez
    Commented Dec 28, 2023 at 13:21
  • Please fix the capitalization errors, otherwise looks good
    – Ahri
    Commented Dec 28, 2023 at 20:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.