1

I'm trying to use Jupiter API to swap tokens via python, and i used basically same code it's been around in this forum, which is:

swap_instruction = swap_tx_response.json()["swapTransaction"]

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

signature = keypair.sign_message(solders.message.to_bytes_versioned(raw_tx.message))

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("rpc_url", headers=headers, json=data)

I'm also running custom "helius RPC" as rpc to send my txs, and i'm finding the problem that some transactions confirm correctly, but others directly doesn't go through the blockchain, showing "no data" in explorer, like this one:

https://solscan.io/tx/2QLTN9mAP9qWR3zQkprPM8k24WpLfi9DoF3qU1E78NBhWpBLrxe7qyVSoL1rB4kYadvpv9Q83NxVEcHHQ7UjSDJV

I don't know what could be causing this as im a bit o a noob on solana, so help would be appreciated.

2 Answers 2

2

If there's no transaction data, then your transaction was never actually executed and included in a block.

Considering the difficulties around landing transactions recently due to priority fees, you may simply need to add some priority fees to your transactions when targeting mainnet-beta.

More information about priority fees at https://solanacookbook.com/references/basic-transactions.html#how-to-change-compute-budget-fee-priority-for-a-transaction

-1

If you're experiencing inconsistent results with transactions not being processed or appearing as "no data" on Solana explorers, here are concise steps to troubleshoot and rectify potential issues, especially when using the Jupiter API for swaps in Python:

Key Points to Check:

  1. Transaction Construction and Signing:

    • Ensure accurate decoding, signing, and encoding of the transaction.
  2. RPC Node Health:

    • Verify that your Helius RPC is fully synced and operational.
  3. Signature Verification:

    • Confirm correct signature generation with the appropriate keypair.
  4. Transaction Confirmation:

    • Use the getTransaction method to verify transaction status directly.
  5. Debugging:

    • Log intermediate steps (e.g., raw_tx, signature) to validate their correctness.

Simplified Code Example:

Assuming you have the transaction instructions (swap_instruction) from Jupiter API and a keypair for signing, the process involves:

  1. Decode the instruction, sign it, and re-encode for submission:
    import base64
    import httpx
    from solders.keypair import Keypair
    from solders.transaction import VersionedTransaction
    
    # Example keypair loading/creation (replace with actual keypair)
    keypair = Keypair.from_secret_key(<your_secret_key_bytes>)
    
    # Decode the transaction, sign, and encode
    raw_tx = VersionedTransaction.from_bytes(base64.b64decode(swap_instruction))
    signature = keypair.sign_message(bytes(raw_tx.message))
    signed_tx = VersionedTransaction.populate(raw_tx.message, [signature])
    encoded_tx = base64.b64encode(bytes(signed_tx)).decode('utf-8')
    
    # Submission
    rpc_url = "your_rpc_url"
    headers = {"Content-Type": "application/json"}
    data = {
        "jsonrpc": "2.0", "id": 1, "method": "sendTransaction",
        "params": [encoded_tx, {"skipPreflight": True, "preflightCommitment": "finalized"}]
    }
    response = httpx.post(rpc_url, headers=headers, json=data)
    print(response.json())
    

Make sure to replace "your_rpc_url" with your actual RPC endpoint and <your_secret_key_bytes> with your keypair's secret key.

General Tips:

  • Always confirm the RPC endpoint (rpc_url) is correct and the node is accessible.
  • For debugging, start with simpler transactions (e.g., SOL transfer) to ensure the basic flow works.
  • If problems persist, consider using a public RPC endpoint temporarily to rule out issues with your custom Helius RPC.

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.