what is the difference between sending a transaction from a client to the Raydium program to make a swap and making your program that does a cpi call to the Raydium program and sending the transaction to your program instead?

I have seen some people doing this and I am wondering if anyone knows the benefits of doing a cpi call vs the other? Are there more chances that it is included in the block are there any benefits regarding speed?

Thank you in advance for your answers.

1 Answer 1


There's some difference between the two approaches. Both will end up locking the same subset of accounts to do the trade, so you don't necessarily get better priority with either approach.

Using a separate program to CPI into Raydium has a few differences. First, you'll incur a higher compute unit usage from whatever logic is performed in your program. On the flip-side, this means you can do extra logic in your program. For example, you can check that you received enough tokens.

  • 1
    Hi thank you for your answer, how can you check that you received enough tokens? I saw some bots using this second approach, and I was wondering if I am missing something. I don't think you can get the amount of tokens back as raydium program doesn't return that value, so there must be something else.
    – kc.sol
    Commented Jan 11 at 12:29
  • 1
    After invoking the raydium program, you can deserialize the token account with spl_token::state::Account::unpack(&token_account_info.data.borrow()).unwrap().amount
    – Jon C
    Commented Jan 11 at 15:08
  • Thanks Jon C, will try it out and let you know how it goes. Is there a way to connect with you directly? From what I saw the bots are sending another transaction for selling, so they could just subscribe to the token account and be notified when the tokens are bought. So I am not sure how doing this benefits them in any way.
    – kc.sol
    Commented Jan 12 at 8:53
  • I couldn't tell you how the other bots work, sorry! and I prefer to keep interactions out in the open to benefit everyone who might run into the same issue.
    – Jon C
    Commented Jan 13 at 10:07
  • @JonC can I use github.com/raydium-io/raydium-cpi-example/tree/master/amm-cpi/… to CPI into raydium amm v4? ty
    – att
    Commented May 31 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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