Skip to main content

Python SDK

import hashlib
import hmac
import json
import time
import requests

class HDWaaSClient:
def __init__(self, api_key: str, secret_key: str, base_url: str = 'https://api.2settle.io'):
self.api_key = api_key
self.secret_key = secret_key
self.base_url = base_url

def _sign(self, method: str, path: str, body: dict = None) -> tuple:
timestamp = str(int(time.time() * 1000))
body_str = json.dumps(body or {}, separators=(',', ':'))
body_hash = hashlib.sha256(body_str.encode()).hexdigest()
payload = f"{timestamp}|{method}|{path}|{body_hash}"
hmac_key = hashlib.sha256(self.secret_key.encode()).hexdigest()
signature = hmac.new(hmac_key.encode(), payload.encode(), hashlib.sha256).hexdigest()
return timestamp, signature, body_str

def _request(self, method: str, path: str, body: dict = None):
timestamp, signature, body_str = self._sign(method, path, body)

headers = {
'Content-Type': 'application/json',
'X-API-Key': self.api_key,
'X-Timestamp': timestamp,
'X-Signature': signature,
}

response = requests.request(
method,
f"{self.base_url}{path}",
headers=headers,
data=body_str if method != 'GET' else None,
)

return response.json()

def create_wallet(self, network: str, crypto: str, metadata: dict = None, expires_in_minutes: int = None):
body = {'network': network, 'crypto': crypto}
if metadata:
body['metadata'] = metadata
if expires_in_minutes:
body['expiresInMinutes'] = expires_in_minutes
return self._request('POST', '/v1/wallets', body)

def get_wallet(self, wallet_id: str):
return self._request('GET', f'/v1/wallets/{wallet_id}', {})

def list_wallets(self, status: str = None, limit: int = 50, offset: int = 0):
params = []
if status:
params.append(f"status={status}")
params.append(f"limit={limit}")
params.append(f"offset={offset}")
path = f"/v1/wallets?{'&'.join(params)}"
return self._request('GET', path, {})


# Usage
client = HDWaaSClient('pk_your_api_key', 'sk_your_secret_key')

# Create USDT deposit address
result = client.create_wallet(
network='trc20',
crypto='USDT',
metadata={'orderId': 'ORD-12345'},
expires_in_minutes=60
)

print(f"Deposit address: {result['wallet']['address']}")

# Check deposit status
status = client.get_wallet(result['wallet']['id'])
print(f"Status: {status['wallet']['status']}")