Skip to main content

Python SDK for interacting with the 4Mica payment network.

Project description

4Mica Python SDK

An asyncio-first Python port of the Rust SDK for interacting with the 4Mica payment network. It mirrors the Rust SDK surface: user (payer) flows, recipient flows, X402 helpers, and strongly-typed request/response models.

Installation

pip install .           # from this repo
# Optional: remuneration requires BLS decoding
pip install 'sdk-4mica[bls]'

Quick start

import asyncio
from fourmica_sdk import (
    Client, ConfigBuilder, PaymentGuaranteeRequestClaims, SigningScheme
)

async def main():
    cfg = ConfigBuilder().from_env().wallet_private_key("0x...").build()
    client = await Client.new(cfg)

    # Deposit 1 ETH
    await client.user.deposit(10**18)

    # Create a tab as the recipient
    tab_id = await client.recipient.create_tab(
        user_address="0xUser",
        recipient_address=client.recipient._recipient_address,  # or set explicitly
        erc20_token=None,
        ttl=3600,
    )

    # Sign a payment as the user
    claims = PaymentGuaranteeRequestClaims.new(
        "0xUser",
        client.recipient._recipient_address,
        tab_id,
        10**17,
        timestamp=int(__import__("time").time()),
        erc20_token=None,
    )
    sig = await client.user.sign_payment(claims, SigningScheme.EIP712)

    # Issue a guarantee as the recipient
    cert = await client.recipient.issue_payment_guarantee(claims, sig.signature, sig.scheme)
    print("Guarantee:", cert)

    await client.aclose()

asyncio.run(main())

X402 helper

from fourmica_sdk import X402Flow, PaymentRequirements

flow = X402Flow.from_client(client)
payment = await flow.sign_payment(payment_requirements, user_address="0xUser")
resp = await flow.settle_payment(payment, payment_requirements, facilitator_url="https://api.4mica.xyz/core/")

Configuration

  • wallet_private_key (required)
  • rpc_url (defaults to https://api.4mica.xyz/)
  • ethereum_http_rpc_url and contract_address are auto-fetched from the facilitator unless provided.

Environment variables mirror the Rust SDK:

4MICA_WALLET_PRIVATE_KEY
4MICA_RPC_URL
4MICA_ETHEREUM_HTTP_RPC_URL
4MICA_CONTRACT_ADDRESS
4MICA_ADMIN_API_KEY

Notes

  • All methods are async; use asyncio.run or your event loop of choice.
  • Remuneration requires py-ecc (pip install 'sdk-4mica[bls]') to expand BLS signatures into the on-chain format.
  • Numeric values accept int or hex/decimal strings and are serialized to 0x-prefixed hex when sent to the facilitator.

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

sdk_4mica-0.2.0.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

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

sdk_4mica-0.2.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file sdk_4mica-0.2.0.tar.gz.

File metadata

  • Download URL: sdk_4mica-0.2.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for sdk_4mica-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d5e6815dd497908308de12889f331c423ef3a5b43d09e95215d734e5ca58676f
MD5 2d2443ed067c28ba6a4ad57584cf9106
BLAKE2b-256 7b4b5fb24d48c9466814b7040d13a36bdfca5a4ccee1667bfae951241c0605cf

See more details on using hashes here.

File details

Details for the file sdk_4mica-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sdk_4mica-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for sdk_4mica-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42e2309345f99abdad2065eee59933b4b23f4c620f283fd20c908c1da4c8bb15
MD5 bba82a2a3a3d8865ea8c113df07e88d2
BLAKE2b-256 a9b5193b2cc19744590c32cd25595099625640ded1e7cad3f8a9f62ee7ffc0c6

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