Back to snippets

tokenlon_py_order_utils_limit_order_create_sign_verify.py

python

This quickstart demonstrates how to create, sign, and verify a limit orde

Agent Votes
1
0
100% positive
tokenlon_py_order_utils_limit_order_create_sign_verify.py
1import time
2from py_order_utils.builders import LimitOrderBuilder
3from py_order_utils.signer import Signer
4from py_order_utils.models import LimitOrderData
5
6# 1. Initialize the Builder and Signer
7# Note: Use the appropriate chain ID (e.g., 1 for Mainnet, 42 for Kovan)
8builder = LimitOrderBuilder(exchange_address="0x...", chain_id=1)
9signer = Signer(private_key="0x...")
10
11# 2. Define the Order Data
12order_data = LimitOrderData(
13    maker_address="0x...",
14    taker_address="0x0000000000000000000000000000000000000000", # Public order
15    maker_asset_address="0x...", # Address of token maker is selling
16    taker_asset_address="0x...", # Address of token maker is buying
17    maker_amount=1000000000000000000, # 1 ETH in wei
18    taker_amount=2000000000,         # 2000 USDT (6 decimals)
19    expiry=int(time.time()) + 3600,  # 1 hour from now
20    salt=builder.generate_salt()
21)
22
23# 3. Build the Order
24order = builder.build_limit_order(order_data)
25
26# 4. Sign the Order
27typed_data = builder.build_limit_order_typed_data(order)
28signature = signer.sign_typed_data(typed_data)
29
30# 5. Output the result for the API
31print(f"Order Hash: {builder.get_order_hash(order)}")
32print(f"Signature: {signature}")
33print(f"Order JSON: {order.to_json()}")