Skip to main content

Python SDK for Mosaic bounty contracts on Base — transactions, signing, events, and metadata

Project description

mosaic-sdk

Python SDK for Mosaic bounty contracts on Base. Build and sign on-chain transactions, decode contract events, and load bounty metadata from Arweave or HTTP.

This package complements the TypeScript SDK (usemosaicxyz/ts-sdk), which also integrates the Mortar read API. The Python SDK focuses on wallet/RPC workflows and log indexing.

Requirements

  • Python 3.12+
  • An RPC endpoint for Base mainnet (chain id 8453)
  • A deployed Mosaic bounties contract address
  • A private key only when you need to sign and broadcast transactions via MosaicClient.send

Install

From a clone of this repository:

uv sync
# or: pip install -e .

Dependencies are declared in pyproject.toml (eth-account, eth-abi, httpx, loguru, etc.).

Quick start

Build transactions (no private key)

Use MosaicClient to assemble unsigned transaction dicts (chainId, to, data, value). Pass them to your own signer or hardware wallet.

import asyncio
from mosaic_sdk import MosaicClient, canonical_metadata_hash

client = MosaicClient(
    rpc_url="https://mainnet.base.org",
    contract_address="0x0c7fad7C9bBaD0BE62aAc867c6069d7Aad7Cb361",
)

metadata = {"version": 1, "title": "Fix login redirect", "brief": "..."}
metadata_hash = canonical_metadata_hash(metadata)
metadata_uri = "ar://your-tx-id"  # or any URI your deployment accepts

approve_tx = client.approve_usdc(50_000_000)  # 50 USDC (6 decimals)
create_tx = client.create_bounty(
    metadata_uri=metadata_uri,
    metadata_hash=metadata_hash,
    reward_amount=25_000_000,
    duration=86_400,
)

Sign and broadcast

Provide private_key when calling send. Never commit keys; load from environment variables or a secret manager in your application.

import os
import asyncio

client = MosaicClient(
    rpc_url=os.environ["RPC_URL"],
    contract_address=os.environ["CONTRACT_ADDRESS"],
    private_key=os.environ["PRIVATE_KEY"],
)

async def main():
    tx_hash = await client.send(client.create_bounty(...))
    print(tx_hash)

asyncio.run(main())

Decode events

from mosaic_sdk import decode_event

# `log` is an Ethereum log object (e.g. from `eth_getLogs`)
event = decode_event(log)
# {"name": "BountyCreated", "bountyId": 1, "poster": "0x...", ...}

Load and verify metadata

import asyncio
from mosaic_sdk import load_metadata, canonical_metadata_hash

async def main():
    metadata = await load_metadata(
        "ar://your-tx-id",
        expected_hash=canonical_metadata_hash({...}),
    )

asyncio.run(main())

load_metadata resolves ar:// URIs via the Arweave gateway (default https://arweave.net) and checks the canonical JSON hash when expected_hash is set.

Defaults (Base mainnet)

Constant Value
BASE_CHAIN_ID 8453
BASE_USDC Base native USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)

MosaicClient enforces Base + native USDC for v1. Override is not supported until a future version documents other networks.

API surface

MosaicClient — transaction builders and RPC sender:

  • approve_usdc, create_bounty, submit, dispute
  • finalize, advance_review_cursor, refund_submission_bond, refund_expired
  • resolve_dispute, cancel_resolved_dispute
  • withdraw, withdraw_to
  • Admin: set_config, set_allowed_duration, set_grout, set_admin
  • send(tx) — estimate gas, sign, and broadcast (requires private_key)

decode_event(log) — decode Mosaic bounty contract logs.

canonical_metadata_hash(metadata) — keccak256 of canonical JSON (sort_keys, compact separators).

load_metadata(uri, expected_hash?, gateway?) — fetch JSON metadata and optionally verify hash.

Configuration and secrets

Keep sensitive values out of source control:

Variable Purpose
RPC_URL Base JSON-RPC URL (may include provider API keys in the path)
CONTRACT_ADDRESS Mosaic bounties contract
PRIVATE_KEY Hex-encoded key for send only

See .env.example for a template. Copy to .env locally (gitignored).

Related projects

License

MIT

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

mosaic_sdk-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

mosaic_sdk-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mosaic_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.2","id":"zara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mosaic_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4005a9e5b5f0660c4141cb01f7c609921b04a46f2110ea5effdda85d49741782
MD5 e1136e3f4c4db60197a591e70d5a98bb
BLAKE2b-256 a4ab9c2d485a2a5239d971ff7c773e21261447044af34ad97b46beb6bb8ff74a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mosaic_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.2","id":"zara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mosaic_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb2531c536a18ce1df3bbeb565bc1dd010c2456e27f4045fe50ecb516fd872a7
MD5 7997661d8111214f7b5ca83ba63d89f1
BLAKE2b-256 8112781c3980e73c1621685659205caf385f80d19a578045b41f36d93e8930cd

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