1

I'm in the last step of implementing the Jupiter swap API. I got all the swap quote all the way to the swap transaction. Now I have a base64 encoded swap transaction from Jupiter Swap API and need to convert and sign it then finally send the transaction to the network. The official guide is with JS/TS.

How to do this in Rust?

const transactionBase64 = swapResponse.swapTransaction const transaction = VersionedTransaction.deserialize(Buffer.from(transactionBase64, 'base64')); console.log(transaction); transaction.sign([wallet]); const transactionBinary = transaction.serialize(); console.log(transactionBinary); 

There's a VersionedTransaction struct here, but it doesn't have any initializer with a base64 encoded string. Am I missing something?

1 Answer 1

2

VersionedTransaction has serde support (with the "serde" feature flag), it has no native method to deserialize from the Jupiter base64 string. For deserializing from bytes, you'll likely need to use an external crate like bincode or another serialization format that Solana uses.

It would look something like:

// required imports use solana_transaction::VersionedTransaction; use base64; // decode your base64 tx to bytes let transaction_bytes = base64::decode(transaction_base64)?; // deserialize using bincode (Solana's standard format) let mut transaction: VersionedTransaction = bincode::deserialize(&transaction_bytes)?; // sign the transaction // you'll need the recent blockhash and your keypair transaction.signatures = vec![your_keypair.sign_message(&transaction.message.serialize())]; // serialize for sending let serialized = bincode::serialize(&transaction)?; 

But for a more end-to-end and thorough approach, you should check the jupiter swap api client repo

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.