Python SDK for the ChainMerge multichain transaction decoder API.
Project description
chainmerge-sdk (Python)
Python SDK for the ChainMerge multichain transaction decoder API.
Use this SDK to call GET /api/decode and get a normalized transaction object across multiple chains.
Requirements
- Python
3.9+ - A running ChainMerge API instance (
base_url)
Install
From PyPI:
pip install chainmerge-sdk
From this repository (editable install):
cd sdk/python
python3 -m pip install -e .
Quick Start
from chainmerge_sdk import ChainMergeClient
client = ChainMergeClient(
base_url="https://chainmerge-api.onrender.com",
# api_key="optional-api-key",
timeout=15.0,
)
tx = client.decode_tx(
chain="ethereum",
tx_hash="0xd5d0587189f3411699ae946baa2a7d3ebfaf13133f9014a22bab6948591611ad",
)
print("chain:", tx.chain)
print("tx_hash:", tx.tx_hash)
print("sender:", tx.sender)
print("receiver:", tx.receiver)
for action in tx.actions:
print(action.action_type, action.token, action.amount)
Use a Custom RPC URL
Pass rpc_url when you want to override the backend default RPC endpoint for a specific request.
tx = client.decode_tx(
chain="polkadot",
tx_hash="0xyour_tx_hash",
rpc_url="https://polkadot.api.subscan.io",
)
Error Handling
from chainmerge_sdk import (
ChainMergeAPIError,
ChainMergeClient,
ChainMergeTransportError,
)
client = ChainMergeClient(base_url="https://chainmerge-api.onrender.com")
try:
tx = client.decode_tx(chain="ethereum", tx_hash="0x...")
except ChainMergeAPIError as err:
# API returned non-2xx
print("api error:", err)
print("status_code:", err.status_code)
print("code:", err.code)
print("retryable:", err.retryable)
except ChainMergeTransportError as err:
# Network issue or invalid JSON payload
print("transport error:", err)
Returned Data Shape
decode_tx() returns NormalizedTransaction with:
chain: strtx_hash: strsender: str | Nonereceiver: str | Nonevalue: str | Noneevents: list[NormalizedEvent]actions: list[Action]
NormalizedEvent fields:
event_typetokenfrom_addressto_addressamountraw_program
Action fields:
action_typefrom_addressto_addressamounttokenmetadata
Supported Chains
solanaethereumcosmosaptossuipolkadotbitcoinstarknet
Passing an unsupported chain raises ValueError.
API Reference
from chainmerge_sdk import ChainMergeClient
client = ChainMergeClient(
base_url: str,
api_key: str | None = None,
timeout: float = 15.0,
)
tx = client.decode_tx(
chain: str,
tx_hash: str,
rpc_url: str | None = None,
)
# New 1.1.0 Methods:
client.health() -> HealthResponse
client.examples() -> ExamplesResponse
client.get_metrics() -> dict
client.decode_and_index_tx(chain, tx_hash, rpc_url=None) -> NormalizedTransaction
client.lookup_indexed_tx(chain, tx_hash) -> NormalizedTransaction
client.list_recent_indexed_txs(limit=10) -> list[NormalizedTransaction]
JavaScript-style alias is also available:
tx = client.decodeTx(chain="ethereum", hash="0x...", rpcUrl=None)
Local Development
From sdk/python:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .
python -m unittest discover -s tests -v
GitHub Actions Publish
This repository includes .github/workflows/publish-python-sdk.yml:
- Push tag
python-sdk-vX.Y.Zto publish to PyPI. - Manual run (
workflow_dispatch) supportstestpypiorpypi.
Required repository secrets:
PYPI_API_TOKENTEST_PYPI_API_TOKEN
Tag release example:
git tag python-sdk-v0.1.0
git push origin python-sdk-v0.1.0
Manual local publish example (TestPyPI):
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Manual local publish example (PyPI):
python3 -m build
python3 -m twine upload dist/*
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 chainmerge_sdk-1.1.2.tar.gz.
File metadata
- Download URL: chainmerge_sdk-1.1.2.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a8372d6d4b871d02616ee07ae7812307630d93a8c69b412e9890aeba083106e
|
|
| MD5 |
755fdab05557550133beebd45a3c677e
|
|
| BLAKE2b-256 |
c818cd7dd08442f34c5c7829e023dae1e6ea1293470eb398b9617663a2897e50
|
File details
Details for the file chainmerge_sdk-1.1.2-py3-none-any.whl.
File metadata
- Download URL: chainmerge_sdk-1.1.2-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27225c2c8c6334ca8bd0180d60935af9512b597325fc534d5e653554df074176
|
|
| MD5 |
cf55274ce8dee7770c38bb666c861657
|
|
| BLAKE2b-256 |
aab9d1b7304b3bbd393ee001514e381a816f6be5776acc2aeb36a777777a437f
|