jup-ag / jupiter-quote-api-node

102 stars 34 forks source link

Account is frozen, custom program error: 0x11 #32

Open zhongchunfengyyds opened 4 months ago

zhongchunfengyyds commented 4 months ago
import { clusterApiUrl, Connection, Keypair, VersionedTransaction } from '@solana/web3.js'
import { Wallet } from '@project-serum/anchor'
import bs58 from 'bs58'
import * as dotenv from 'dotenv'
import axios from 'axios'

dotenv.config()

async function main() {
    try {
        const SOLANA_CLUSTER = clusterApiUrl('mainnet-beta');
        const connection = new Connection(SOLANA_CLUSTER, 'confirmed');

        const wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(process.env.PRIVATE_KEY || '')))

        const quoteResponse = await axios.get('https://quote-api.jup.ag/v6/quote', {
            params: {
                inputMint: 'So11111111111111111111111111111111111111112',
                outputMint: '21rweMLGYeMNonHW7H3xa5py17X6ZFRcHirCp9inRBQA',
                amount: 100000000,
                slippageBps: 50,
                swapMode: 'ExactOut',
                onlyDirectRoutes: true,
                asLegacyTransaction: false,
            },
        })

        console.dir(quoteResponse.data, { depth: null })
        const swapResponse = await axios.post('https://quote-api.jup.ag/v6/swap', {
            quoteResponse: quoteResponse.data,
            userPublicKey: wallet.publicKey.toString(),
            wrapAndUnwrapSol: true,
            prioritizationFeeLamports: 'auto',
        })

        console.log('Swap Response:', swapResponse.data)

        // Deserialize the transaction
        const swapTransactionBuf = Buffer.from(swapResponse.data.swapTransaction, 'base64')
        const transaction = VersionedTransaction.deserialize(swapTransactionBuf)

        // Sign the transaction
        transaction.sign([wallet.payer])

        // We first simulate whether the transaction would be successful
        const { value: simulatedTransactionResponse } = await connection.simulateTransaction(transaction, {
            replaceRecentBlockhash: true,
            commitment: 'processed',
        })
        const { err, logs } = simulatedTransactionResponse

        if (err) {
            // Simulation error, we can check the logs for more details
            // If you are getting an invalid account error, make sure that you have the input mint account to actually swap from.
            console.error('Simulation Error:')
            console.error({ err, logs })
            return
        }

        // Execute the transaction
        const rawTransaction = transaction.serialize()
        const txid = await connection.sendRawTransaction(rawTransaction, {
            skipPreflight: true,
        })

        console.log(`Transaction initiated. Txid: ${txid}`)
        try {
            await connection.confirmTransaction(txid)
        } catch (error) {
            console.error('Confirmation error:', error)
        }
        console.log(`View transaction on Solscan: https://solscan.io/tx/${txid}`)
    } catch (error) {
        console.error('Error:', error)
    }
}

main()

When I perform a transaction when the outputMint is 21rweMLGYeMNonHW7H3xa5py17X6ZFRcHirCp9inRBQA, it will prompt Program log: Error: Account is frozen, custom program error: 0x11. But I can conduct transactions on the front-end page of Jupiter Aggregator. Other coins do not have this situation and can be successfully traded.

jkllx commented 3 months ago

sir, same issue, Did you solve the problem? thx