create_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: create_transaction

Description

The 'create_transaction' method creates a Solana transaction from a base64-encoded string containing the swap transaction data.

Parameters

  • 'swap_transaction_data' (str): The base64-encoded string containing the swap transaction data.

Returns

'VersionedTransaction': A promise that resolves to a 'VersionedTransaction' object.

Example

This example demonstrates using both 'get_swap' and 'create_transaction' methods.

async def perform_swap_and_create_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}");
    except Exception as e:
        print(f"An error occurred: {e}")

perform_swap_and_create_transaction();

Implementation Details

This method converts the 'swap_transaction_data' from a base64-encoded string to a buffer and deserializes it into a 'VersionedTransaction'.

Last updated