1

I'm encountering an issue while trying to execute a transaction on the Solana blockchain.(swaping solana to bonk using jupiter swap api) When attempting to execute the transaction, I receive the following error message: {'jsonrpc': '2.0', 'error': {'code': -32602, 'message': "invalid transaction: Transaction loads an address table account that doesn't exist"}, 'id': 1} here is the code that i"m using

    import requests
    from solana.rpc.api import Client 
    from solders.keypair import Keypair
    from solders.pubkey import Pubkey
    from solana.rpc.api import Client
    from solders.transaction import VersionedTransaction
    from solana.transaction import Transaction
    from solders.system_program import TransferParams, transfer
    from solana.rpc.api import Client
    import base64
    import httpx
    import solders 
    http_client = Client("https://api.devnet.solana.com")
    pv_key =  "mypvkey"
    wallet = Keypair.from_base58_string(pv_key)

    print(wallet.pubkey())
    r = requests.get('https://quote-api.jup.ag/v6/quote?inputMint=So11111111111111111111111111111111111111112\
    &outputMint=DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263\
    &amount=100000000\
    &slippageBps=50')

    if r.status_code == 200:
            quote_response = r.json()
            response = requests.post('https://quote-api.jup.ag/v6/swap', json={
                "quoteResponse": quote_response,
                "userPublicKey": str(wallet.pubkey()),  # Corrected attribute name
                "wrapAndUnwrapSol": True
            })

    if response.status_code == 200:
            swap_instruction = response.json()["swapTransaction"]

            raw_tx = solders.transaction.VersionedTransaction.from_bytes(base64.b64decode(swap_instruction))

            message_to_sign = bytes(raw_tx.message)
            signature = wallet.sign_message(message_to_sign)

            signed_tx = solders.transaction.VersionedTransaction.populate(raw_tx.message, [signature])
            encoded_tx = base64.b64encode(bytes(signed_tx)).decode('utf-8')
            headers = {
                "Content-Type": "application/json"
            }
            data = {
                "jsonrpc": "2.0",
                "id": 1,
                "method": "sendTransaction",
                "params": [
                    encoded_tx,
                    {
                        "skipPreflight": True,
                        "preflightCommitment": "finalized",
                        "encoding": "base64",
                        "maxRetries": None,
                        "minContextSlot": None
                    }
                ]
            }
            tx_response = httpx.post("https://api.devnet.solana.com", headers=headers, json=data)
            print(tx_response.json())
    else : 
            print("error") ```

1 Answer 1

1

Usually this is caused by you trying to send the transaction on the wrong network. That looks likely to be the case here - Jupiter's API will be returning a transaction on mainnet and you're trying to send it on devnet.

Jupiter's transaction contains address lookup tables that exist on mainnet but not devnet. Note that this won't be the only issue, the blockhash will also be invalid on devnet, and other accounts might not exist either. You'll need to send that transaction on mainnet.

1
  • thanks it works but it returns a json with the result that when seatched on solscan gives no data 285kb1ZnAnt42pP4g2Jvb98rwVvyvTzDHDnRuPmrLUpf7ASFRbcBCe7JAsYtaG2Dpche9vtoyd2NxzXY1v1L4Ayg Commented Feb 6 at 16:43

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.