Documentation Index
Fetch the complete documentation index at: https://docs.mandate.md/llms.txt
Use this file to discover all available pages before exploring further.
What is MandateWallet?
MandateWallet wraps MandateClient with a viem signing layer. You call a single method like transfer() and it handles the entire flow: estimate gas, compute intentHash, validate against your policies, sign locally, broadcast, post the event, and wait for on-chain confirmation. Your private key never leaves your machine.
Constructor
MandateWallet accepts a MandateWalletConfig object. You must provide either a privateKey or a signer, not both.
Variant 1: Private key
Pass a raw hex private key directly. The SDK creates a viem wallet client internally.Variant 2: External signer
Wrap any existing wallet (Privy, AgentKit, Fireblocks) with theExternalSigner interface. The SDK delegates signing to your implementation.
MandateWalletConfig
| Field | Type | Required | Description |
|---|---|---|---|
runtimeKey | string | Yes | Agent runtime key (mndt_test_* or mndt_live_*) |
chainId | number | Yes | 84532 (Base Sepolia) or 8453 (Base Mainnet) |
privateKey | `0x${string}` | One of | Raw hex private key |
signer | ExternalSigner | One of | Custom wallet implementing ExternalSigner |
baseUrl | string | No | Mandate API URL. Default: https://app.mandate.md |
rpcUrl | string | No | Custom RPC endpoint. Default: chain-specific public RPC |
Properties
wallet.address
Synchronous getter. Returns the wallet’s 0x${string} address. If you use an external signer whose getAddress() returns a Promise, this throws until the address is resolved. Use getAddress() instead.
wallet.getAddress()
Async-safe version. Returns Promise<0x${string}>. Works with both private key and external signer variants. Always prefer this in async contexts.
Methods
wallet.transfer(to, rawAmount, tokenAddress, opts?)
Send an ERC20 token transfer with full policy enforcement. The SDK encodes the ERC20 transfer(address,uint256) calldata internally using the built-in ABI.
| Name | Type | Description |
|---|---|---|
to | `0x${string}` | Recipient address |
rawAmount | string | Token amount in smallest unit (e.g. '5000000' for 5 USDC) |
tokenAddress | `0x${string}` | ERC20 contract address |
opts.reason | string | Human-readable reason for audit log |
opts.waitForConfirmation | boolean | Wait for on-chain confirmation. Default: true |
TransferResult
intentHash -> call rawValidate -> sign locally -> broadcast -> postEvent -> waitForConfirmation.
wallet.sendEth(to, valueWei, opts?)
Send native ETH (or the chain’s native token). Same policy enforcement flow as transfer, but with 0x calldata and the value in wei.
wallet.sendTransaction(to, calldata, valueWei?, opts?)
General-purpose method for calling any contract function. Use this when you need to interact with a contract beyond simple ERC20 transfers.
| Name | Type | Default | Description |
|---|---|---|---|
to | `0x${string}` | Target contract address | |
calldata | `0x${string}` | Encoded function call | |
valueWei | string | '0' | Native token value in wei |
opts.reason | string | Reason for audit log | |
opts.waitForConfirmation | boolean | true | Wait for on-chain confirmation |
wallet.sendTransactionWithApproval(to, calldata, valueWei?, opts?)
Same as sendTransaction, but catches ApprovalRequiredError and polls for human approval before proceeding. Use this when your policy includes approval rules and the agent should wait rather than fail.
| Name | Type | Description |
|---|---|---|
opts.approvalTimeoutMs | number | Max time to wait for approval before timing out |
opts.onApprovalPending | (intentId, approvalId) => void | Called when approval is requested |
opts.onApprovalPoll | (status: IntentStatus) => void | Called on each poll iteration |
rawValidate throws ApprovalRequiredError, the method calls onApprovalPending, then polls waitForApproval until the human approves or rejects. On approval, it signs, broadcasts, and confirms as usual. On rejection or timeout, it throws.
wallet.transferWithApproval(to, rawAmount, tokenAddress, opts?)
ERC20 transfer with built-in approval wait support. Combines the ERC20 encoding of transfer() with the approval polling of sendTransactionWithApproval().
opts as sendTransactionWithApproval.
wallet.x402Pay(url, opts?)
Execute an x402 payment flow. The method probes the URL, detects a 402 Payment Required response, parses the payment details from the X-Payment-Required header, transfers the requested amount, and retries the original request with the transaction hash.
| Name | Type | Description |
|---|---|---|
url | string | The URL to request |
opts.headers | Record<string, string> | Additional request headers |
opts.reason | string | Reason for audit log |
Response object from the retry request. If the initial request does not return 402, it returns that response directly (no payment attempted).
wallet.preflightTransfer(params)
Lightweight policy check without signing or broadcasting. Uses the action-based validate() endpoint under the hood. Use this to check if a transfer would pass your policies before committing to the full flow.
| Name | Type | Required | Description |
|---|---|---|---|
params.to | `0x${string}` | Yes | Recipient address |
params.amount | string | Yes | Human-readable amount (e.g. '50') |
params.token | string | No | Token symbol (e.g. 'USDC') |
params.reason | string | Yes | Reason for the transfer |
PreflightResult with allowed, intentId, requiresApproval, and blockReason fields.
ExternalSigner interface
Implement this interface to use any wallet provider withMandateWallet. You provide the signing logic; Mandate handles policy validation.
sendTransaction receives a fully prepared transaction object. Sign it, broadcast it, and return the transaction hash. getAddress can be sync or async depending on your wallet provider.
Example: wrapping ethers.js
Error handling
AllMandateWallet methods throw typed errors on failure. Catch them to build resilient agent logic.
WithApproval method variants if you want the SDK to handle ApprovalRequiredError automatically instead of catching it yourself.
Next Steps
MandateClient
Low-level API methods for validate, register, and status polling.
Error Handling
Typed error classes, catch patterns, and recovery strategies.
Handle Approvals
Build approval workflows with polling and callbacks.
x402 Payments
Pay-per-request with the x402 protocol.