forked from floxxih/ChainBridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_swap.py
More file actions
48 lines (38 loc) · 1.36 KB
/
Copy pathcreate_swap.py
File metadata and controls
48 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""End-to-end example: create an XLM→BTC swap order with the Python SDK.
Run with:
pip install chainbridge
export CHAINBRIDGE_API_KEY=cb_xxx
export CHAINBRIDGE_SENDER=GA...
python create_swap.py
"""
from __future__ import annotations
import os
import sys
from chainbridge import ChainBridgeClient
def main() -> int:
api_key = os.environ.get("CHAINBRIDGE_API_KEY")
sender = os.environ.get("CHAINBRIDGE_SENDER")
if not api_key or not sender:
print("Set CHAINBRIDGE_API_KEY and CHAINBRIDGE_SENDER first.", file=sys.stderr)
return 1
with ChainBridgeClient(api_key=api_key) as client:
fees = client.market.estimate_fees(
from_chain="stellar", to_chain="bitcoin", from_amount="1000000000"
)
print(f"Estimated fees: {fees}")
order, secret, hash_lock = client.create_swap_order(
from_chain="stellar",
to_chain="bitcoin",
from_asset="XLM",
to_asset="BTC",
from_amount="1000000000",
to_amount="10000",
sender_address=sender,
expiry_seconds=86_400,
)
print(f"Created order: {order.order_id}")
print(f"Hash-lock (share with counterparty): {hash_lock}")
print(f"Secret (KEEP PRIVATE until claim): {secret}")
return 0
if __name__ == "__main__":
raise SystemExit(main())