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="http://127.0.0.1:8080",
    # 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="http://127.0.0.1:8080")

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,
)

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-0.1.2.tar.gz (8.5 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-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chainmerge_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for chainmerge_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f7783aaaf0dc6c8c7ea0fd0a9099ff364fc33654904046649673533c1cd9b6d4
MD5 aeb6bb6f5777511f0af9f261eb3cab5c
BLAKE2b-256 fd701cb252c1fad048ab18efe2a03474c6e1d2bbeff57ecf6046e441a2c2e203

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chainmerge_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for chainmerge_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ccee4fbb96421e72f254ecd325d8d0629ab15655f6a730f3f5b770e89589a6ec
MD5 a7b53757ed9c246a0ef08546df38ccf1
BLAKE2b-256 2915d7663d045e51236bffcba16573f25cbde74b13b2d6fdc65e7ed4462b2f33

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