Creating Swaps
This guide provides a detailed walkthrough on how to execute both Order-Based Swaps (custodial/invoicing) and Atomic Swaps (direct node-to-node) using the Kaleido Python SDK. These examples leverage the Pydantic models fromkaleido_sdk to ensure type safety and precise API interactions.
1. Creating a Swap Order
Swap orders involve locking in a rate via a quote and receiving a deposit address (or invoice) to fund the swap.Prerequisites & Imports
Python
Step-by-Step Flow
Step 1: Find the Desired Asset ID
Before requesting a quote, you often need the exact RGB Asset ID. You can discover this via the market API.Python
Step 2: Request a Quote
Request a price quote for trading BTC for the RGB asset.Python
Step 3: Create the Swap Order
Use the quote’sfrom_asset and to_asset (they are full SwapLeg objects with amounts) when creating the order.
Python
2. Executing an Atomic Swap
Atomic Swaps allow direct, trustless node-to-node exchange using RGB Lightning Nodes. You must run an RLN node alongside this client.Prerequisites & Imports
Python
Step-by-Step Flow
Step 1: Get a Quote
Obtain a quote for the asset pair you wish to swap.Python
Step 2: Initialize the Swap
Initialize the swap lock with the Maker based on the RFQ.Python
Step 3: Whitelist on your Taker Node
Your RLN node needs to be aware of theswapstring to process the incoming swap correctly.
Python
Step 4: Execute the Swap
Finalize the execution with the Maker by providing your node’s details.Python