Safe Unified Account Multichain Signing
These methods of the Safe Unified Account (SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2) sign UserOperations for several chains with a single signature, using a Merkle tree of the UserOperation hashes. Create the account, build each UserOperation and send it as described on Safe Unified Account. For an ordinary single-chain transaction, use signUserOperation instead.
The examples use SafeMultiChainSigAccountV1. Every method works the same on SafeMultiChainSigAccountV2.
Methods at a Glance
| Method | Signature | Returns |
|---|---|---|
| signUserOperations | signUserOperations(userOperationsToSign: UserOperationToSign[], privateKeys: string[]) | string[] |
| signUserOperationsWithSigners | signUserOperationsWithSigners(userOperationsToSign: UserOperationToSign[], signers: ReadonlyArray<ExternalSigner<MultiOpSignContext<UserOperationV9>>>) | Promise<string[]> |
| getMultiChainSingleSignatureUserOperationsEip712Hash (static) | getMultiChainSingleSignatureUserOperationsEip712Hash(userOperationsToSign: UserOperationToSign[], overrides?: { safe4337ModuleAddress?; entrypointAddress? }) | string |
| getMultiChainSingleSignatureUserOperationsEip712Data (static) | getMultiChainSingleSignatureUserOperationsEip712Data(userOperationsToSign: UserOperationToSign[], overrides?: { safe4337ModuleAddress?; entrypointAddress? }) | { domain; types; messageValue } |
| formatSignaturesToUseroperationsSignatures (static) | formatSignaturesToUseroperationsSignatures(userOperationsToSign: UserOperationToSignWithOverrides[], signerSignaturePairs: SignerSignaturePair[]) | string[] |
For gas sponsorship across chains, see Gas Sponsorship.
Methods
signUserOperations
Signs multiple UserOperations across different chains with a single signing session. Builds a Merkle tree from the UserOperation hashes, signs the Merkle root, and returns an array of signatures (one per UserOperation) each containing the Merkle proof for its chain.
If only one UserOperation is provided, falls back to single-chain signing.
In AbstractionKit v0.3.5, UserOperationToSignWithOverrides split the previous catch-all overrides field into options for normal signing options and webAuthnSignatureOverrides for WebAuthn-specific signature encoding values.
- example.ts
- Param Types
- Return Type
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
// Create UserOperations for each chain
const userOp1 = await smartAccount.createUserOperation([tx], nodeUrl1, bundlerUrl1);
const userOp2 = await smartAccount.createUserOperation([tx], nodeUrl2, bundlerUrl2);
// Sign all UserOperations with one signing session
const signatures = smartAccount.signUserOperations(
[
{ userOperation: userOp1, chainId: 11155111n },
{ userOperation: userOp2, chainId: 11155420n },
],
[ownerPrivateKey],
);
// Attach signatures
userOp1.signature = signatures[0];
userOp2.signature = signatures[1];
| key | type | description |
|---|---|---|
userOperationsToSign | UserOperationToSign[] | Array of UserOperations with their target chain IDs and optional validity windows |
privateKeys | string[] | Private keys of the Safe owners to sign with |
UserOperationToSign
| key | type | description |
|---|---|---|
chainId | bigint | Target chain ID for this UserOperation |
userOperation | UserOperationV9 | The UserOperation to sign |
validAfter? | bigint | Timestamp the signature will be valid after |
validUntil? | bigint | Timestamp the signature will be valid until |
| key | type | description |
|---|---|---|
signatures | string[] | Array of signatures, one per UserOperation. Each contains the Merkle proof for its respective chain. If only one UserOperation is provided, falls back to single-chain signing. |
Source code
signUserOperationsWithSigners
Multi-op variant that signs a Merkle-rooted bundle of UserOperations using one or more ExternalSigners instead of raw private keys. One signing session covers every chain in the bundle.
Since v0.3.8, this path accepts typed-data-only signers such as fromViemWalletClient as well as raw-hash signers. Pass chainId inside each UserOperationToSign item so the SDK can build the per-chain typed-data payloads.
signUserOperationsWithSigners(
userOperationsToSign: UserOperationToSign[],
signers: ExternalSigner<MultiOpSignContext<UserOperationV9>>[],
): Promise<string[]>
- example.ts
- Param Types
- Return Type
import { SafeMultiChainSigAccountV1 as SafeAccount, fromViem } from "abstractionkit";
import { privateKeyToAccount } from "viem/accounts";
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
const viemAccount = privateKeyToAccount("0x...");
const signatures = await smartAccount.signUserOperationsWithSigners(
[
{ userOperation: userOp1, chainId: 11155111n },
{ userOperation: userOp2, chainId: 11155420n },
],
[fromViem(viemAccount)],
);
userOp1.signature = signatures[0];
userOp2.signature = signatures[1];
| Param Name | Param Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| userOperationsToSign | UserOperationToSign[]
| UserOperations with their chain IDs and optional validity windows. | |||||||||||||||
| signers | ExternalSigner<MultiOpSignContext<UserOperationV9>>[] | One signer per owner required by the threshold, in any order. The built-in adapters |
| Param Name | Param Type | Description |
|---|---|---|
| signatures | Promise<string[]> | One formatted signature per input UserOperation, in the same order. |
See External Signers for the full list of adapters, and the multi-chain add-owner example for a full end-to-end flow.
Source code
getMultiChainSingleSignatureUserOperationsEip712Hash
Static method. Computes the EIP-712 hash of the Merkle tree root for a set of UserOperations. This is the hash that wallet signers (browser extensions, hardware wallets) sign to approve multiple cross-chain operations at once.
- example.ts
- Param Types
- Return Type
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
const hash = SafeAccount.getMultiChainSingleSignatureUserOperationsEip712Hash([
{ userOperation: userOp1, chainId: 11155111n },
{ userOperation: userOp2, chainId: 11155420n },
]);
| key | type | description |
|---|---|---|
userOperationsToSign | UserOperationToSign[] | Array of UserOperations with their target chain IDs |
overrides? | object | Optional overrides for module and entrypoint addresses |
overrides?.safe4337ModuleAddress? | string | Override the Safe 4337 module address. Defaults to the Safe 4337 multi-chain signature module. |
overrides?.entrypointAddress? | string | Override the EntryPoint address. Defaults to EntryPoint v0.9. |
UserOperationToSign
| key | type | description |
|---|---|---|
chainId | bigint | Target chain ID for this UserOperation |
userOperation | UserOperationV9 | The UserOperation to sign |
validAfter? | bigint | Timestamp the signature will be valid after |
validUntil? | bigint | Timestamp the signature will be valid until |
| key | type | description |
|---|---|---|
hash | string | The EIP-712 hash of the Merkle tree root, ready for signing by wallets |
Source code
getMultiChainSingleSignatureUserOperationsEip712Hash
getMultiChainSingleSignatureUserOperationsEip712Data
Static method. Returns the EIP-712 typed data components (domain, types, message value) for a multi-chain Merkle tree root. Use this for wallet-compatible signing via eth_signTypedData_v4.
- example.ts
- Param Types
- Return Type
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
const { domain, types, messageValue } =
SafeAccount.getMultiChainSingleSignatureUserOperationsEip712Data([
{ userOperation: userOp1, chainId: 11155111n },
{ userOperation: userOp2, chainId: 11155420n },
]);
// Use with a wallet provider
const signature = await wallet.signTypedData(domain, types, messageValue);
| key | type | description |
|---|---|---|
userOperationsToSign | UserOperationToSign[] | Array of UserOperations with their target chain IDs |
overrides? | object | Optional overrides for module and entrypoint addresses |
overrides?.safe4337ModuleAddress? | string | Override the Safe 4337 module address. Defaults to the Safe 4337 multi-chain signature module. |
overrides?.entrypointAddress? | string | Override the EntryPoint address. Defaults to EntryPoint v0.9. |
UserOperationToSign
| key | type | description |
|---|---|---|
chainId | bigint | Target chain ID for this UserOperation |
userOperation | UserOperationV9 | The UserOperation to sign |
validAfter? | bigint | Timestamp the signature will be valid after |
validUntil? | bigint | Timestamp the signature will be valid until |
| key | type | description |
|---|---|---|
domain | { verifyingContract: string } | The EIP-712 domain with the Safe 4337 module as verifying contract |
types | Record<string, { name: string; type: string }[]> | The EIP-712 type definitions for multi-chain operations |
messageValue | { merkleTreeRoot: string } | The message containing the Merkle tree root of all UserOperation hashes |
Source code
getMultiChainSingleSignatureUserOperationsEip712Data
formatSignaturesToUseroperationsSignatures
Static method. Formats EIP-712 signatures (from wallet signing) into UserOperation signatures with Merkle proofs. Use this after signing with getMultiChainSingleSignatureUserOperationsEip712Hash or getMultiChainSingleSignatureUserOperationsEip712Data.
- example.ts
- Param Types
- Return Type
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
const userOpsToSign = [
{ userOperation: userOp1, chainId: 11155111n },
// Since v0.3.5, generic signing options and WebAuthn signature overrides
// use separate fields instead of the previous catch-all `overrides` field.
{
userOperation: userOp2,
chainId: 11155420n,
options: { safe4337ModuleAddress: "0x..." },
webAuthnSignatureOverrides: { isInit: userOp2.factory != null },
},
];
const signerSignaturePairs = [
{ signer: ownerAddress, signature: eip712Signature },
];
const signatures = SafeAccount.formatSignaturesToUseroperationsSignatures(
userOpsToSign,
signerSignaturePairs,
);
userOp1.signature = signatures[0];
userOp2.signature = signatures[1];
| key | type | description |
|---|---|---|
userOperationsToSign | UserOperationToSignWithOverrides[] | Array of UserOperations with their target chain IDs and optional per-operation options / WebAuthn signature overrides |
signerSignaturePairs | SignerSignaturePair[] | Array of signer address and signature pairs from EIP-712 signing |
UserOperationToSignWithOverrides
| key | type | description |
|---|---|---|
chainId | bigint | Target chain ID for this UserOperation |
userOperation | UserOperationV9 | The UserOperation to sign |
validAfter? | bigint | Timestamp the signature will be valid after |
validUntil? | bigint | Timestamp the signature will be valid until |
options? | SafeSignatureOptions | Per-operation signing options such as the Safe 4337 module address. In v0.3.5 this replaced the generic overrides field for non-WebAuthn options. |
webAuthnSignatureOverrides? | WebAuthnSignatureOverrides | Per-operation WebAuthn signature encoding overrides, such as isInit or WebAuthn verifier addresses. In v0.3.5 this replaced the WebAuthn-specific values previously carried in overrides. |
| key | type | description |
|---|---|---|
signatures | string[] | Array of formatted signatures with Merkle proofs, one per UserOperation |
Source code
formatSignaturesToUseroperationsSignatures
Gas Sponsorship
Use CandidePaymaster for gas sponsorship with multichain operations. The paymaster uses a two-phase flow: commit (before signing) and finalize (after signing).
import { CandidePaymaster } from "abstractionkit";
// One paymaster instance per chain
const paymaster1 = new CandidePaymaster("https://api.candide.dev/public/v3/11155111");
const paymaster2 = new CandidePaymaster("https://api.candide.dev/public/v3/11155420");
// Phase 1: Commit (before signing)
const commitContext = { signingPhase: "commit" as const };
const commitOverrides = { preVerificationGasPercentageMultiplier: 20 };
const [{ userOperation: commitOp1 }, { userOperation: commitOp2 }] = await Promise.all([
paymaster1.createSponsorPaymasterUserOperation(
smartAccount, userOperation1, bundlerUrl1, undefined, commitContext, commitOverrides
),
paymaster2.createSponsorPaymasterUserOperation(
smartAccount, userOperation2, bundlerUrl2, undefined, commitContext, commitOverrides
),
]);
userOperation1 = commitOp1;
userOperation2 = commitOp2;
// Sign here with signUserOperations...
// Phase 2: Finalize (after signing)
const finalizeContext = { signingPhase: "finalize" as const };
const [{ userOperation: finalOp1 }, { userOperation: finalOp2 }] = await Promise.all([
paymaster1.createSponsorPaymasterUserOperation(
smartAccount, userOperation1, bundlerUrl1, undefined, finalizeContext
),
paymaster2.createSponsorPaymasterUserOperation(
smartAccount, userOperation2, bundlerUrl2, undefined, finalizeContext
),
]);
userOperation1 = finalOp1;
userOperation2 = finalOp2;