raydium-io / raydium-sdk-V2-demo

Open-source Typescript SDK demos
50 stars 31 forks source link

Error when trying to swap from default script #88

Closed SwatX18 closed 12 hours ago

SwatX18 commented 5 days ago

Hi,

I tried to swap from the default script with default execution command. Command: yarn dev src/amm/swap.ts

In the config file, I tried with TxVersion.V0 & TxVersion.LEGACY Legacy give me an error more detailed:

C:\Users\XXXX\Desktop\raydium-sdk-V2\node_modules\@solana\web3.js\src\utils\send-and-confirm-transaction.ts:94
      throw new SendTransactionError({
            ^
SendTransactionError: Transaction XXXXXX resulted in an error.
Status: ({"err":{"InstructionError":[0,"IllegalOwner"]}}).
Catch the `SendTransactionError` and call `getLogs()` on it for full details.
    at sendAndConfirmTransaction (C:\Users\XXXX\Desktop\raydium-sdk-V2\node_modules\@solana\web3.js\src\utils\send-and-confirm-transaction.ts:94:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async execute (C:\Users\XXXX\Desktop\raydium-sdk-V2\node_modules\@raydium-io\raydium-sdk-v2\src\common\txTool\txTool.ts:261:15) {
  signature: 'XXXXXXXX',
  transactionMessage: 'Status: ({"err":{"InstructionError":[0,"IllegalOwner"]}})',
  transactionLogs: undefined
}

And this is the execution logs at start:

bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
connect to rpc https://api.mainnet-beta.solana.com/ in mainnet
computed swap 0.000001 WSOL to 0.000097694 POPCAT, minimum amount out 0.000096717 POPCAT
simulate tx string: [
  'XXXXXXXX'
]

I also tried with the personal rpc url and it failed again.

All I do is clone the repo -> configure the config file -> run the default command swap

Can you help me please ?

PS: I'm on Windows 11 with Node v20.18.0

cruzshia commented 3 days ago

try replacing a paid rpc node, public default rpc node https://api.mainnet-beta.solana.com have lots of issues.

SwatX18 commented 3 days ago

try replacing a paid rpc node, public default rpc node https://api.mainnet-beta.solana.com have lots of issues.

Okay, do you have any suggestion for the rpc node to use? A website name?

cruzshia commented 3 days ago

we use paid rpc owned by ourself and we can't provide you those. I would suggest you to subscribe paid service because free resources usually used by lots of ppl and don't have good quality.

SwatX18 commented 3 days ago

I tried again and again, it's just not working... I tried on my mac too. I used like 5 different rpc providers.

This is my new error:

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {
  code: 'ERR_UNHANDLED_REJECTION'
cruzshia commented 2 days ago

please ensure

  1. pull latest demo code and delete node_modules re-run yarn install
  2. use a paid rpc node not free one
  3. ensure your wallet have enough balance for swap

I tested it again and it still work well, it's not related to you use mac or not.

test tx: https://explorer.solana.com/tx/3FSHfioU3JW1dbypzaAEwMmdFdCFHFeiJhf5GWk4NWJDSCog14hjhekgYnVtPVcaS143gDE6tfmnmeMkgT1XvGpe

config code:

export const connection = new Connection('YOUR_RPC_URL')
export const txVersion = TxVersion.V0 // or TxVersion.LEGACY
const cluster = 'mainnet'

let raydium: Raydium | undefined
export const initSdk = async (params?: { loadToken?: boolean }) => {
  if (raydium) return raydium
  console.log(`connect to rpc ${connection.rpcEndpoint} in ${cluster}`)
  raydium = await Raydium.load({
    owner,
    connection,
    cluster,
    disableFeatureCheck: true,
    disableLoadToken: !params?.loadToken,
    blockhashCommitment: 'finalized',
  return raydium
}

result screen shot

Screen Shot 2024-10-15 at 11 05 27 AM
SwatX18 commented 23 hours ago

It still doesn't work with 2 different paid RPCs...

Error with LEGACY because V0 has no stack to show: TransactionExpiredBlockheightExceededError: Signature XXXX has expired: block height exceeded.

If I have to buy a $600 dedicated RPC to get it to work, there's no point.

cruzshia commented 15 hours ago

TransactionExpiredBlockheightExceededError usually means you need to set higher priority fees or there's some error in your code. try set higher priority fees or paste your full code and wallet address here. https://github.com/raydium-io/raydium-sdk-V2-demo?tab=readme-ov-file#error-block-height-exceeded

image

I am pretty sure original demo code is totally fine cuz I have tested it for couple times. also suggest you to use swap api for easier tx manipulation

sol to popcat swap test tx: https://explorer.solana.com/tx/aauhx8nvsJC1fgDKjhqHxUtaUqpvjLvWGZc1Tm5Uj4YjtLR73gAbzuiuUUQWr4yQgJD2RH1L73YyRCL2aSuoR4q

cruzshia commented 12 hours ago

due to no issues was found for demo and sdk, I will close this issue.