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.1.0.tar.gz (22.7 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.1.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sdk_4mica-0.1.0.tar.gz
  • Upload date:
  • Size: 22.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 f736013cccf2e831fc37ebdb46553a4046cf3a0c7ae10b93189c54dfe31323da
MD5 3035bf440532878a97f3f564d77b56a3
BLAKE2b-256 0d537e9b73f0e009072b86c461debbe78ae67025afae6741255852208add1f30

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sdk_4mica-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 250b1b1ed2a5c9d0cb041f42cd4afbf5aa532d5da7cfbba2ce8722ca4bca4ed9
MD5 8ebce0930524a736e83cc1b084d67efb
BLAKE2b-256 40e05dbce5747953c572172d73809032c22da6cb828e24f325c8d729463cbcfb

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