Skip to main content

Configuration

sdk-4mica needs a signer and uses defaults for everything else. Set options on ClientBuilder, or let ClientBuilder::from_env read 4MICA_* environment variables.

ClientBuilder

Client::builder() returns a ClientBuilder. Chain the setters you need, then call connect().
connect() builds the configuration and then reaches core for its public parameters, which is why it is async and fallible. Its error is the umbrella sdk_4mica::Error, wrapping one of:
  • ConfigError::Missing when no signer is set.
  • ConfigError::InvalidValue when a URL or address does not parse.
  • ClientError::Rpc when core cannot be reached.
  • ClientError::Initialization when core does not accept the payment payload version this SDK signs.
To separate the two steps, call build() for a Config and pass it to Client::connect(config) later.
You normally do not set ethereum_http_rpc_url or contract_address. Core publishes both. The SDK connects to the Ethereum endpoint on first use and checks its chain id against core’s. A client that only takes gasless routes never opens that connection.

Networks and the facilitator

The builder starts on Base mainnet with Base’s hosted facilitator. network(...) moves both together.
A builder with no network connects to Base mainnet and moves real funds. Select the network explicitly in any code that moves money, and start on Base Sepolia with a test wallet.
network and rpc_url replace each other, so the last one you call wins. facilitator_url is independent of call order. Without a facilitator, every operation is the wallet’s own transaction and the wallet pays gas. To skip the facilitator for one operation, pin .self_funded() on its builder; see gasless routes. See the network table for shorthands, CAIP-2 ids, and URLs.

Using environment variables

ClientBuilder::from_env() reads these variables and returns a builder. With neither 4MICA_NETWORK nor 4MICA_RPC_URL set, the builder stays on Base mainnet. A shell cannot export a name that starts with a digit. Put the variables in a .env file and load it in your program, for example with the dotenvy crate:
Setters you call on the returned builder win over the environment: here network overrides 4MICA_NETWORK. from_env() returns ConfigError::InvalidValue for an unknown network, a malformed private key, or a refresh margin that does not parse as an unsigned integer.
The Rust SDK reads the 4MICA_* names only. It does not read the FOURMICA_* names the TypeScript and Python SDKs accept.

Signers

Client<S> is generic over its signer. S can be any type that implements alloy’s Signer trait: a local key, a hardware wallet, or a remote key service. The default is PrivateKeySigner.
What the signer must implement depends on the route you take: A signing-only backend can therefore run every gasless flow. It needs transaction signing only for routes where the wallet sends its own transaction. An unpinned .send() counts as one of those, because it may fall back to a self-funded transaction. client.signer_address() returns the address the client signs as. Every deposit credits that account.

Authentication

Core’s authenticated endpoints take a bearer access token. Credentials decides where it comes from. Connecting never triggers a sign-in, because the public parameters are public. With SIWE, the first authenticated call signs in for you. Call client.login() to sign in ahead of time:
login() returns AuthError::MissingConfig when the credentials are not SIWE. Use a static token, or turn credentials off:
Pass the bare access token. The SDK adds the Bearer prefix to the Authorization header itself.
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, withdraw, sign payments, and settle cleared cycles.