Skip to main content

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 the ExternalSigner interface. The SDK delegates signing to your implementation.

MandateWalletConfig

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.
Parameters: Returns: TransferResult
Internal flow: estimate gas (with 1.2x buffer) -> compute intentHash -> call rawValidate -> sign locally -> broadcast -> postEvent -> waitForConfirmation.
Pass amounts in the token’s smallest unit (raw). For USDC with 6 decimals, 5 USDC = '5000000'. The SDK does not perform decimal conversion.

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.
Parameters:

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.
Extra options: Flow: If 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().
Accepts the same 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.
Parameters: Returns: The final 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.
Parameters: Returns: PreflightResult with allowed, intentId, requiresApproval, and blockReason fields.
preflightTransfer uses human-readable amounts (e.g. '50' for 50 USDC), unlike transfer() which requires raw amounts in the token’s smallest unit.

ExternalSigner interface

Implement this interface to use any wallet provider with MandateWallet. 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

All MandateWallet methods throw typed errors on failure. Catch them to build resilient agent logic.
Use the 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.