Skip to main content

iWAN client for Wanchain

Project description

iWAN Python Client

A Python client for Wanchain iWAN (WebSocket) RPC API.

English | 中文


English

Installation

pip install iwan

Or from source:

git clone https://github.com/Nevquit/iWAN.git
cd iWAN
python setup.py install

Usage

import json
from iwan import IwanClient

# Configuration
URL = 'wss://apitest.wanchain.org:8443/ws/v3/'
API_KEY = 'your_api_key'
SECRET_KEY = 'your_secret_key'

# Initialize Client
client = IwanClient(URL, API_KEY, SECRET_KEY)

# Prepare Request
request = {
    "jsonrpc": "2.0",
    "method": "getBalance",
    "params": {
        "address": "your_wanchain_address",
        "chainType": "WAN"
    }
}

# Send Request
try:
    response = client.send_request(request)
    print(json.dumps(response, indent=2))
finally:
    client.close()

Features

  • Automatic Signing: Automatically generates timestamps and signatures for your requests.
  • Request ID Handling: Ensures unique IDs for each request using uuid4 if not provided.
  • Retry Mechanism: Built-in retry logic that validates response IDs.
  • SSL Support: Option to skip SSL verification if needed.

API Reference

IwanClient(url, api_key, secret_key, timeout=30, skip_ssl_verify=False)

  • url: WebSocket endpoint (e.g., wss://api.wanchain.org:8443/ws/v3/).
  • api_key: Your iWAN API key.
  • secret_key: Your iWAN secret key.
  • timeout: Connection timeout in seconds.
  • skip_ssl_verify: Set to True to skip SSL certificate verification.

send_request(request_src, retry=10)

  • request_src: Dictionary containing the JSON-RPC request.
  • retry: Number of retries on network error or ID mismatch.

中文

安装

pip install iwan

或从源码安装:

git clone https://github.com/Nevquit/iWAN.git
cd iWAN
python setup.py install

使用示例

import json
from iwan import IwanClient

# 配置信息
URL = 'wss://apitest.wanchain.org:8443/ws/v3/'
API_KEY = 'your_api_key'
SECRET_KEY = 'your_secret_key'

# 初始化客户端
client = IwanClient(URL, API_KEY, SECRET_KEY)

# 准备请求
request = {
    "jsonrpc": "2.0",
    "method": "getBalance",
    "params": {
        "address": "your_wanchain_address",
        "chainType": "WAN"
    }
}

# 发送请求
try:
    response = client.send_request(request)
    print(json.dumps(response, indent=2))
finally:
    client.close()

项目特性

  • 自动签名:自动为请求生成时间戳(timestamp)和签名(signature)。
  • 请求 ID 处理:如果请求中未提供 ID,自动使用 uuid4 生成唯一 ID。
  • 重试机制:内置重试逻辑,并校验响应中的 ID 是否与请求匹配。
  • SSL 支持:支持跳过 SSL 证书校验。

项目结构

iwan_project/
├── src/
│   └── iwan/               # 源代码目录
│       ├── __init__.py
│       └── client.py       # 核心客户端逻辑
├── tests/                  # 测试代码
├── pyproject.toml          # 核心配置文件
├── README.md               # 项目说明
└── LICENSE                 # 许可证

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iwan-0.1.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iwan-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file iwan-0.1.1.tar.gz.

File metadata

  • Download URL: iwan-0.1.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for iwan-0.1.1.tar.gz
Algorithm Hash digest
SHA256 add0eae222b6e79ae148268eabcff0d90d75b6e2f26fd5c215c5965c4184cc58
MD5 7c0df59d06fb5e0b96323982fbd8994a
BLAKE2b-256 93a04f89e70e81fdcf32ef74c1ba50d7dee28f8269d4e5193094058df2962c92

See more details on using hashes here.

File details

Details for the file iwan-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: iwan-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for iwan-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30f8a515da0d19f996277b025525d809eb3bb0a8856dd17793a037dcb90f2b9c
MD5 8173868bc574296a2ce39608537bb0b4
BLAKE2b-256 3e9037396f0e69e799a75072860d3e75f861acedce9e253fab6128c55bbbd846

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page