Skip to main content

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: str
  • tx_hash: str
  • sender: str | None
  • receiver: str | None
  • value: str | None
  • events: list[NormalizedEvent]
  • actions: list[Action]

NormalizedEvent fields:

  • event_type
  • token
  • from_address
  • to_address
  • amount
  • raw_program

Action fields:

  • action_type
  • from_address
  • to_address
  • amount
  • token
  • metadata

Supported Chains

  • solana
  • ethereum
  • cosmos
  • aptos
  • sui
  • polkadot
  • bitcoin
  • starknet

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.Z to publish to PyPI.
  • Manual run (workflow_dispatch) supports testpypi or pypi.

Required repository secrets:

  • PYPI_API_TOKEN
  • TEST_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


Download files

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

Source Distribution

chainmerge_sdk-1.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

chainmerge_sdk-1.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file chainmerge_sdk-1.1.1.tar.gz.

File metadata

  • Download URL: chainmerge_sdk-1.1.1.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

Hashes for chainmerge_sdk-1.1.1.tar.gz
Algorithm Hash digest
SHA256 3965543789b91171e735e3bdf675340250d863490e61f5acb7c3dcbc40379275
MD5 0533919202d0a72ae84478e8d38294b1
BLAKE2b-256 0251cdebe056413b04dd6c619c90d2ab3c24e9fde9fb87240ec9106915b00ff9

See more details on using hashes here.

File details

Details for the file chainmerge_sdk-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: chainmerge_sdk-1.1.1-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

Hashes for chainmerge_sdk-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 262f3d7f46b7004675c5e0991c0d4d45121865fd9c22c3fd71ba0ac4f0e5272d
MD5 61b8f95c439e71a71bfe83781c1314a8
BLAKE2b-256 cb67713956c790a21d7b935c1227210ebfc845aee3024d2da3752ba7b6425783

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