A Python SDK for the KyberSwap Aggregator API
Project description
KyberSwap Python SDK
This Python SDK provides a simple and easy-to-use interface for interacting with the KyberSwap Aggregator API. It allows you to fetch swap routes, build transactions, and execute swaps on supported chains. The SDK is designed to be modular, extensible, and developer-friendly.
Before Anything, Thank You KyberSwap!
We would like to extend our heartfelt thanks to KyberSwap for providing such an amazing and free service. Your aggregator API has made it incredibly easy for developers to integrate decentralized swaps into their applications. Keep up the great work!
Developed with ❤️ by Harsh from BaseNerds/Basehound.
For questions or feedback, feel free to reach out!
Features
- Chain Selection: Easily switch between supported chains (e.g., Ethereum, Polygon, BSC, Arbitrum, etc.).
- Route Fetching: Fetch the best swap route for a given token pair.
- Swap Execution: Build and execute swaps with encoded transaction data.
Installation - Tested on Python 3.10 or higher.
- Pip install Library
pip install kyberswap_py_sdk
-
Or Directly Clone the repository:
git clone https://github.com/your-repo/kyberswap-python-sdk.git cd kyberswap-python-sdk pip install -r requirements.txt
Usage - Example with Polygon
1. Initialize the SDK
To use the SDK, initialize it with the desired chain, RPC URL, and your private key (optional for read-only operations).
from kyberswap_py_sdk import KyberSwapSDK, ChainName, Token
import asyncio
# Define tokens - 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE represents ETH
token_in = Token(
address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
chain_id=ChainId.BASE,
decimals=18,
symbol="ETH",
name="Ethereum"
)
token_out = Token(
address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
chain_id=ChainId.BASE,
decimals=18,
symbol="USDC",
name="USDC"
)
token_in_amount = 0.1
# Initialize SDK
private_key = "YOUR_PRIVATE_KEY" # Replace with your actual private key
sdk = KyberSwapSDK(
chain=ChainName.BASE,
rpc_url="YOUR_RPC_OF_CHOICE",
private_key=private_key)
# get swap route
swap_route = asyncio.run(sdk.get_swap_route(token_in,
token_out,
amount_in=token_in_amount))
# get info about swap route
print(f"Swap Route: {swap_route}")
route_gas = int(swap_route['routeSummary']['gas'])
route_gas_price = int(swap_route['routeSummary']['gasPrice'])
# # Execute swap
# # Legacy Transaction (Type 0)
# tx_receipt = asyncio.run(sdk.execute_swap(
# token_in,
# token_out,
# amount_in=token_in_amount,
# gas=route_gas*1.5,
# gas_fee_wei= route_gas_price,
# txn_type=0
# ))
# # EIP-2930 Transaction (Type 1)
# tx_receipt = asyncio.run(sdk.execute_swap(
# token_in,
# token_out,
# amount_in=0.1,
# slippage_tolerance=10,
# gas=int(route_gas*3),
# gas_fee_wei=int(route_gas_price*1.5),
# txn_type=1,
# access_list=[{
# "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", # USDC contract
# "storageKeys": ["0x0000000000000000000000000000000000000000000000000000000000000000"]
# }]
# ))
# EIP-1559 Transaction (Type 2)
tx_receipt = asyncio.run(sdk.execute_swap(
token_in,
token_out,
amount_in=token_in_amount,
slippage_tolerance=10,
gas=route_gas*3,
gas_fee_wei=route_gas_price*1.5,
txn_type=2,
max_priority_fee_wei=route_gas_price*1.1
))
if tx_receipt:
print(f"Swap executed successfully! Transaction: {tx_receipt}")
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kyberswap_py_sdk-0.2.8.tar.gz.
File metadata
- Download URL: kyberswap_py_sdk-0.2.8.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c89b3825637573bb41ded11b315f6ca52f6e2c00bafb96a9123b180aa04f709
|
|
| MD5 |
a8d709c55622b0794dc2d8e1854ea3eb
|
|
| BLAKE2b-256 |
16dac9497454456a0738db1c2cd298d587f85e4ab9a11af171b33949d050a0d3
|
File details
Details for the file kyberswap_py_sdk-0.2.8-py3-none-any.whl.
File metadata
- Download URL: kyberswap_py_sdk-0.2.8-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2db89a825f994139246f928bac0590494879b9fb8eb6c6170bb1baf6642ebbf
|
|
| MD5 |
d0acb4c361dbf968a9910b0a0a2de9f5
|
|
| BLAKE2b-256 |
61d5a95ec2329b60df54c97cd8289e3d1086cd1dc1c06bc385326788d3878cd4
|