Skip to main content

Configuration

sdk-4mica needs a signer and uses defaults for everything else. Pass keyword arguments to FourMica.connect, or let it read FOURMICA_* environment variables.

FourMica.connect options

connect raises a ConfigError when no signer is given, when both private_key and signer are, or when a network, URL, or protocol name is invalid. A malformed spend amount raises InvalidParamsError here, not on the first payment.
With no network, the session connects to Base mainnet and its hosted facilitator, so funds are real. Pass network explicitly in every program, and start on a testnet with a test wallet.

Using environment variables

With neither private_key nor signer, FourMica.connect() reads its configuration from the environment.
Arguments you pass still win: FourMica.connect(network="ethereum-sepolia") overrides FOURMICA_NETWORK. FOURMICA_NETWORK takes precedence over FOURMICA_RPC_URL. With neither variable set and no network argument, the session connects to Base mainnet. A variable set to the empty string counts as unset. When you pass private_key or signer, the environment is not read at all. FOURMICA_NETWORK is ignored in that case, so pass network yourself.
The older 4MICA_* names still work. Setting both names of one variable to different values is a ConfigError. Prefer FOURMICA_*: a shell cannot export a name that starts with a digit.
To read from somewhere other than the process environment, pass a mapping: FourMica.connect(env={"FOURMICA_WALLET_PRIVATE_KEY": key, "FOURMICA_NETWORK": "base-sepolia"}).

Using a custom signer

To integrate a remote signer, KMS, or MPC wallet, pass an object that follows the EvmSigner protocol as signer. It needs an address property and three coroutines:
The SDK signs payments, checkpoints, and gasless authorizations as raw 32-byte digests through sign_hash, and the SIWE login message through sign_message. Return each signature in the 65-byte r || s || v form, as hex or bytes. A remote signer signs payments and gasless deposits and withdrawals. It cannot send a transaction or read the wallet, so self-funded routes raise a ClientError, deposit skips its wallet balance check, and withdrawals() needs a local key.

Coinbase CDP wallet

Use create_cdp_account for a Coinbase CDP MPC wallet whose private key never leaves CDP. It needs the cdp extra: pip install "sdk-4mica[cdp]".
The session does not close a signer you pass. The outer async with closes the CDP client.

Advanced: exact control

FourMica is a facade over Client. For anything it does not cover, await client.low_level() returns the session’s Client, already configured. To build a Client yourself, build a Config with ConfigBuilder and pass it to Client.connect.
ethereum_http_rpc_url and contract_address are fetched from the core service by default. The SDK validates the connected chain id but does not verify the contract address or code. Only override these if you need values that differ from the server defaults.
A ConfigBuilder with no network or rpc_url call builds a Base mainnet configuration. network() raises a ConfigError for a name it does not know. It accepts ethereum (eip155:1), which is coming soon and has no hosted facilitator yet, so a known name is not proof that a network is live. build() raises one when a signer or wallet key is missing, a URL, key, or address is malformed, or the auth refresh margin is not a non-negative integer. An Ethereum RPC endpoint is only used by paths that read chain state or send transactions. A client that only signs never touches the chain.

SIWE authentication

Auth is enabled by default, and the first authenticated call to core logs in automatically. Connecting never triggers a login, because the bootstrap routes are public. Use a static token instead of SIWE, or turn credentials off entirely:
client.login() raises a ClientError when auth is not configured, which is the case with a bearer token or after disable_auth().
Never commit private keys. Use a test wallet while you develop and a dedicated service wallet, hardware-backed signer, MPC wallet, or hosted key management system in production.
Start on Base Sepolia (eip155:84532) with small amounts. Once a flow works end to end, move shared values into environment variables and switch networks.

Next steps

Overview

Install the SDK and see the capabilities at a glance.

Client operations

Deposit collateral, sign payments, issue guarantees, and settle cleared cycles.