Karrot - Spiderswap Package
  • Introduction
  • How to Obtain Your API Key
  • NPM
    • Swap Overview
      • getSwapRaw
      • getSwap
      • createTransaction
      • sendTransaction
    • Quote Overview
      • getQuoteRaw
      • getQuote
      • bulkQuote
  • PHP
    • Coming Soon
  • Python
    • Swap Overview
      • get_swap_raw
      • get_swap
      • create_transaction
      • send_transaction
    • Quote Overview
      • get_quote_raw
      • get_quote
      • bulk_quote
Powered by GitBook
On this page
  • Installation
  • Usage
  • Initialization
  • Method: create_transaction
  1. Python
  2. Swap Overview

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'.

Previousget_swapNextsend_transaction

Last updated 11 months ago