send_transaction

Installation

pip install karrotcapital.spiderswap

Usage

Initialization

First, initialize the 'Spiderswap' class with your API key.

from karrotcapital.spiderswap import Spiderswap

spiderswap = Spiderswap(ApiKey);

Method: send_transaction

Description

The 'send_transaction' method sends a Solana transaction to the blockchain, handling retries and confirmation.

Parameters

  • 'rpc_endpoint' (str): The RPC endpoint to send the transaction to.

  • 'transaction' (VersionedTransaction): The transaction object to be sent.

  • 'private_key' (str): The private key of the sender, encoded in base58.

  • 'additional_signers' (List[str] | None): The additional signers that need to sign the transaction for it to be sent (Default is None).

  • 'retries' (float): The amount of retries this function will try to do to execute the transaction (Default is 3).

Returns

'str': A str that resolves to the transaction signature.

Example

This example demonstrates how to use 'get_swap', 'create_transaction', and 'send_transaction' methods.

async def perform_swap_create_and_send_transaction():
    try:
        swap_result = await spiderswap.swap.get_swap(
            'owner_address',
            'from_mint_address',
            'to_mint_address',
            1000000,      # Amount in tokens
            50,           # Slippage percentage
            'provider',
            'pool',
            9             # From Mint Decimals
        );
        print(f"Swap Data: {swap_result}");
        
        transaction = await spiderswap.swap.create_transaction(
            swap_result['base64Transaction']
        )
        print(f"Transaction: {transaction}");
        
        signature = await spiderswap.swap.send_transaction(
            "rpc_endpoint", 
            "transaction", 
            "private_key", 
            swap_response['signers']
        )
        print(f"Transaction Signature: {signature}")
    except Exception as e:
        print(f"An error occurred: {e}")

perform_swap_create_and_send_transaction();

Implementation Details

This method attempts to send the transaction multiple times, updating the blockhash and signing the transaction each time. If it fails after a set number of retries, it throws an error.

Last updated