raydium-io / raydium-sdk

An SDK for building applications on top of Raydium.
https://sdk.raydium.io
GNU General Public License v3.0
360 stars 140 forks source link

Perform a swap with raydium sdk #46

Open ValGuibs opened 10 months ago

ValGuibs commented 10 months ago

I have tried many times with several methods, but I still cannot swap from a token A to a token B, for example exchange 1SOL to X USDC with a slippage and fees choice. What is the simplest method to swap with raydium please? It's really complicated, there are no docs...

de-ltd commented 10 months ago

baffling isn't it.

ertan2002 commented 10 months ago

I'm encountering the same issue here. This SDK is extremely complicated. Honestly, I've never come across such a disorganized, idiotic library in my life. It seems like no one knows anything about it.

ertan2002 commented 10 months ago

Finally I made it :D really what was that.

filipkossoIT commented 10 months ago

Finally I made it :D really what was that. @ertan2002

Would you mind sharing your code so that i can see what i am doing wrong?

I've been trying for a couple of weeks now and it's really difficult when there is no documentation. I have been getting stuck at the makeSwapInstruction. Its throwing this error when i try to send the transaction:

"WalletProviderBase.tsx:63 WalletSendTransactionError: Transaction instruction index 0 has undefined program id"

Thanks in advance!

ertan2002 commented 10 months ago

Finally I made it :D really what was that. @ertan2002

Would you mind sharing your code so that i can see what i am doing wrong?

I've been trying for a couple of weeks now and it's really difficult when there is no documentation. I have been getting stuck at the makeSwapInstruction. Its throwing this error when i try to send the transaction:

"WalletProviderBase.tsx:63 WalletSendTransactionError: Transaction instruction index 0 has undefined program id"

Thanks in advance!

Hi filip

I think you are doing a front-end project and trying to connect your wallet. Unfortunately I am doing a backend proejct and directly perform a swap. So I don't have any idea regarding swapping with a user wallet.

But have you seen a demo project? https://github.com/raydium-io/raydium-frontend

I am using this demo project https://github.com/raydium-io/raydium-sdk-V1-demo it needs a lot of configuration in my case but it is a backend and does not require any wallet approvement.

When I search a demo app, I came across some samples, maybe it will help you

https://abbylow.medium.com/learn-to-build-a-swap-application-with-solana-wallet-adapter-and-raydium-sdk-part-1-20588b9b1ad https://abbylow.medium.com/learn-to-build-a-swap-application-with-solana-wallet-adapter-and-raydium-sdk-part-2-244705cb72a3

https://github.com/abbylow/raydium-swap/

and here is two videos https://www.youtube.com/watch?v=ePJbSv8-9fk https://www.youtube.com/watch?v=zai8CX6OwTg

and actually I find a good documentation https://www.soldev.app/course and the guy on the youtube made a serie for this documentation https://www.youtube.com/watch?v=HavGDGUTmgs&list=PLmAMfj0qP2wwfnuRJQge2ss4sJxnhIqyt

So I read and watch the videos parallel. It is quite useful and learnt a lot of things

hope this helps.

filipkossoIT commented 10 months ago

@ertan2002 Awesome thanks!

i've been checking Abbys tutorial but it was built with an old version and with the intention of only swapping between SOL and RAY. So i could not get much further there.

But thanks for all the other links, I appreciate it! Gonna be reading up on it and hopefully, I can solve it. Probably easiest to try and copy as much as possible from the Raydium frontend at the start until i get it working.

ertan2002 commented 10 months ago

@filipkossoIT Hi I think, I can help you. Just give me your telegram address. I'll show you what I did and maybe it'll give you an idea to connect with a wallet. Because somehow the logic and codes must be same.

Abby used the makeSwapTransaction method but I've used makeSwapInstructionSimple. So as you said, probably Abby's sdk is old one.

I have not tried with a wallet yet. here is a lesson with wallet https://www.soldev.app/course/interact-with-wallets

But I suggest you to start this tutorial from beginning. I've really loved this tutorial and the videos.

VladissaVortex commented 10 months ago

@ertan2002 hey! We're looking for making a swap on backend via Raydium and we certainly need some help. Can you please contact me on Telegram? t.me/vladissa_skinwalker

CVB91 commented 10 months ago

@ertan2002 Hey man, I am also interested. Is there a way to contact you?

filipkossoIT commented 10 months ago

@filipkossoIT Hi I think, I can help you. Just give me your telegram address. I'll show you what I did and maybe it'll give you an idea to connect with a wallet. Because somehow the logic and codes must be same.

Abby used the makeSwapTransaction method but I've used makeSwapInstructionSimple. So as you said, probably Abby's sdk is old one.

I have not tried with a wallet yet. here is a lesson with wallet https://www.soldev.app/course/interact-with-wallets

But I suggest you to start this tutorial from beginning. I've really loved this tutorial and the videos.

I really appreciate it thanks! My TG handle is @filip_kossoIT

Seems like Raydium themself are using makeSwapInstructionSimple so you are most likely right, ill try with that Do you use Liquidity.makeSwapInstructionSimple or TradeV2.makeSwapInstructionSimple? If its the same in the frontend as in the backend when using it

VladissaVortex commented 10 months ago

@ertan2002 , @filipkossoIT , @CVB91, @ValGuibs , @de-ltd , I have created a telegram conversation where you (and all other subsequent interested parties) can figure out how to do this. I think it will make communication easier:

https://t.me/+grk6IHdT4m83YmEy

precious-void commented 10 months ago

Hey folks, finally figured out Raydium SDK swaps. Here is the repo, check it out: precious-void/raydium-swap.

thuthuatna commented 9 months ago

thanks @shtelzerartem why you don't use jupiter instead raydium ?

zitounao commented 8 months ago

Company calls itself decentralized and open source yet the SDK so complex with 0 docs so that very few devs can front run everybody, classic!

stephengardner commented 8 months ago

This is by far the worst in-production-use has-a-repo makes-tons-of-money SDK I've literally ever seen in my entire coding existence. props to the team for making it work. thanks for a headache today

soos3d commented 8 months ago

Hey guys, you can try this one if you're struggling! It's an example of swapping SOL to USDC. Edit the parameters in swapConfig.ts.

https://github.com/chainstacklabs/raydium-sdk-swap-example-typescript

NFTPlayer26 commented 6 months ago

hey guys is there any raydium sdk for python?

coderwithsense commented 5 months ago

It isn't baffling, it's actually not that hard. It works for me