What is the Mandate SDK?
The@mandate.md/sdk package is a TypeScript SDK for the Mandate policy layer. It provides two main classes: MandateClient for low-level API calls, and MandateWallet for a high-level flow that validates, signs, broadcasts, and confirms transactions in one call. The SDK throws typed errors for every failure mode, so your agent can react to policy blocks, approval requests, and circuit breaker trips.
Installation
- bun
- npm
- pnpm
Quick start
Create aMandateClient and validate a transaction against your policies.
validate() method sends an action-based request to the Mandate API. If the transaction passes all 14 policy checks, you get back a PreflightResult with allowed: true and an intentId. If it fails, the SDK throws a typed error with the specific block reason.
Exports
The SDK exposes the following from its main entry point.| Export | Description |
|---|---|
MandateClient | Low-level API wrapper for validate, register, and status polling |
MandateWallet | High-level: validate, sign, broadcast, confirm in one call |
MandateGuard | Alias for MandateWallet |
computeIntentHash | keccak256 of canonical tx string for raw validation |
PolicyBlockedError | Transaction blocked by policy (spend limit, allowlist, schedule) |
MandateBlockedError | Alias for PolicyBlockedError |
CircuitBreakerError | Agent emergency-stopped via circuit breaker |
ApprovalRequiredError | Human approval needed before the transaction can proceed |
RiskBlockedError | Risk scanner blocked the transaction |
MandateError | Base error class for all Mandate errors |
USDC | USDC contract addresses per chain |
CHAIN_ID | Chain ID constants (mainnet + testnet) |
Sub-path import
If you only needMandateClient and want a smaller bundle, import from the /client sub-path. This skips the viem dependency that MandateWallet requires.
How does the SDK handle errors?
Every failure mode has a dedicated error class. Your agent catchesPolicyBlockedError for policy violations, ApprovalRequiredError when human review is needed, CircuitBreakerError when the agent is emergency-stopped, and RiskBlockedError when the risk scanner flags the transaction. All extend MandateError, so you can catch the base class as a fallback. See Error Handling for patterns and examples.
Next Steps
MandateClient
Low-level API methods: validate, register, poll status.
MandateWallet
High-level signing and broadcast flow with viem.
Error Handling
Typed error classes and recommended catch patterns.