0

I'm trying to create swapAmm function on Raydium
I get targetPoolInfo by formatAmmKeysById() and get poolKeys by jsonInfo2PoolKeys()

But when I'm trying to run Liquidity.makeSwapInstructionSimple() always failes
With Error: pubkey.toBase58 is not a function I'm thinking that something wrong with poolkeys

Do you knok, how can I solve it?

UPD: add code
This is swap function:

 async function execSwap(input) {
    const myPublicKey = myKeyPair.publicKey

    let targetPoolInfo;
    while (true) {
        await sleepTime(15000);
        try {
            targetPoolInfo = await formatAmmKeysById(input.targetPool);
            if (targetPoolInfo) {
                break; // If successful, exit the loop
            }
        } catch (error) {
            console.error('pool not found, retrying...');
            
        }
    }
    let poolKeys = jsonInfo2PoolKeys(targetPoolInfo);
  
    const minAmountOut = new TokenAmount(input.outputToken, 1);
    const walletTokenAccounts = await getWalletTokenAccount(connection, myPublicKey)
    console.log(myPublicKey)
    try {
        const instruction = await Liquidity.makeSwapInstructionSimple({
            connection,
            poolKeys,
            userKeys: {
                tokenAccounts: walletTokenAccounts,
                owner: myPublicKey
            },
            amountIn: input.inputTokenAmount,
            amountOut: minAmountOut,
            fixedSide: 'in',
            makeTxVersion,
    })
    } catch (error) {
        console.error(error);
    }

This is "main.js":

const inputToken = quoteToken; // WSOL
    const outputToken = baseToken; // custom token
    const inputTokenAmount = new TokenAmount(inputToken, 10**8);
    const slippage = new Percent(1, 100);
    const wallet = fromKeypair;
    console.log(wallet)
    const res = await execSwap({
          targetPool,
          inputTokenAmount,
          outputToken,
          slippage,
          wallet
      });
1
  • 1
    Please provide some code snippets
    – Joey Meere
    Commented Jun 22 at 1:35

1 Answer 1

1

Without providing code, we can't help much.

However, this error almost always means you're not passing a wallet address/publickey as a PublicKey object.

In your code, wherever you have raw, string, base58 encoded public keys, just throw them inside a PublicKey class from @solana/web3.js, the issue should be resolved.

1
  • I've added the code, can you help me?
    – nyslxj
    Commented Jun 22 at 10:59

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.