im trying to buy a token in solana dex using jupiter dex, i do the next steps:
1- Get Quote 2- With the quote i get the swapTransaction
How do i send this "swapTransaction" variable and create the swap in the live solana network?
I have this code:
import asyncio
import base64
import solders
from solana.transaction import Transaction
from solathon import PublicKey, Keypair
from solana.rpc.types import TxOpts
from solana.rpc.api import Client
from solders import message, transaction
def send_transaction(swap_transaction, opts):
client = Client("https://api.mainnet-beta.solana.com")
sender = Keypair().from_private_key("XXX")
raw_tx = solders.transaction.VersionedTransaction.from_bytes(base64.b64decode(swap_transaction))
signed_txn = sender.sign(bytes(raw_tx))
s_signed_txn = solders.transaction.VersionedTransaction.populate(raw_tx.message, [signed_txn])
encoded_tx = base64.b64encode(bytes(s_signed_txn)).decode('utf-8')
result = client.send_transaction(s_signed_txn, opts)
txid = result.value
print("TxID: {txid}")
async def perform_swap(sent_amount, input_token_mint, output_token_mint):
tmpSwap = "swapTransaction"
opts = TxOpts(skip_preflight=True, max_retries=3)
send_transaction(tmpSwap, opts)
asyncio.run(perform_swap("1000", "So11111111111111111111111111111111111111112", "5HkMzQzo5wiXyNgsWJSm3F8jQYMSaUZ6z5Vd7Z1yCsC9"))