Skip to main content

Safe Unified Account

SafeMultiChainSigAccountV1 is the recommended Safe account class for new AbstractionKit examples. It works for normal single-chain Safe transactions and enables chain abstraction for multichain Safe Accounts. It extends the standard Safe Account with multichain signature support via Merkle trees, allowing you to sign UserOperations for multiple chains with a single signature.

Uses EntryPoint v0.9 and EIP-712 typed data with Merkle proofs.

V1 or V2​

AbstractionKit ships two Safe Unified Account classes. They share the same multichain signature module, signing methods, EIP-712 helpers and Safe Passkey module v0.2.1 WebAuthn defaults. The only difference is the Safe singleton a new account deploys with:

ClassSafe singletonUse it for
SafeMultiChainSigAccountV1Safe L2 v1.4.1Existing V1 accounts and new accounts on Safe v1.4.1
SafeMultiChainSigAccountV2Safe L2 v1.5.0New accounts that want Safe v1.5.0
  • New accounts get different addresses. The singleton is part of the counterfactual address, so the same owners produce a different address with V1 and V2. Keep using the class your users' accounts were created with, or you will predict an address they don't own.
  • Either class attaches a deployed account. The singleton is only used for address derivation and deployment, so new SafeMultiChainSigAccountV1(address) and new SafeMultiChainSigAccountV2(address) behave the same once the account exists.
  • V2 replaces SafeAccountV1_5_0_M_0_3_0. That class, which ran Safe v1.5.0 on EntryPoint v0.7, was removed in AbstractionKit v1.0.0. Use SafeMultiChainSigAccountV2 for Safe v1.5.0 accounts on EntryPoint v0.9.

The examples on this page use SafeMultiChainSigAccountV1. Every method works the same on SafeMultiChainSigAccountV2:

import { SafeMultiChainSigAccountV2 as SafeAccount } from "abstractionkit";

const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);

To pin the singleton explicitly, pass Safe_L2_V1_4_1 or Safe_L2_V1_5_0 (both exported, each with singletonAddress and singletonInitHash) as the safeAccountSingleton override.

Source: SafeMultiChainSigAccountV2

Audits​

To learn more about the contracts, visit the Safe 4337 Multi-Chain Signature Module repository.

Import​

import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";

How to Use​

const ownerPublicAddress = "0xBdbc5FBC9cA8C3F514D073eC3de840Ac84FC6D31";
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);

console.log("Account address:", smartAccount.accountAddress);

The methods below are specific to the Safe Unified Account or override the base class with multichain defaults. The class also inherits the shared Safe methods listed under Methods at a Glance.

Moving from SafeAccountV0_3_0? See Compatibility with Safe Account V3 for the migration steps.

Methods at a Glance​

Methods of SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2. The multichain methods, which sign UserOperations for several chains with one signature, are on Safe Unified Account Multichain Signing, together with multichain gas sponsorship.

MethodSignatureReturns
constructornew SafeMultiChainSigAccountV1(accountAddress: string, overrides?: { safe4337ModuleAddress?; entrypointAddress?; onChainIdentifierParams?; onChainIdentifier?; safeAccountSingleton? })SafeMultiChainSigAccountV1
initializeNewAccount (static)initializeNewAccount(owners: Signer[], overrides?: InitCodeOverrides)InstanceType<T>
createUserOperationcreateUserOperation(transactions: MetaTransaction[], providerRpc?: string | Transport | JsonRpcNode, bundlerRpc?: string | Transport | Bundler, overrides?: CreateUserOperationV9Overrides)Promise<UserOperationV9>
estimateUserOperationGasestimateUserOperationGas(userOperation: UserOperationV9, bundlerRpc: string | Transport | Bundler, overrides?)Promise<[bigint, bigint, bigint]>
signUserOperationsignUserOperation(userOperation: UserOperationV9, privateKeys: string[], chainId: bigint, options?: SafeSignatureOptions)string
signUserOperationssignUserOperations(userOperationsToSign: UserOperationToSign[], privateKeys: string[])string[]
signUserOperationsWithSignerssignUserOperationsWithSigners(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[]

Shared Safe methods​

Inherited from the base SafeAccount class and shared by every Safe class. They work the same on SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2; where the Unified Account differs, the shared section says so.

MethodPurposeDocumented on
sendUserOperationSend a signed UserOperation to the bundlerTransactions and Signing
signUserOperationWithSignersSign one UserOperation with ExternalSigners (viem, ethers, passkeys, HSMs)Transactions and Signing
createAccountCallDataSingleTransaction, createAccountCallDataBatchTransactionsEncode MetaTransactions as account calldataTransactions and Signing
getUserOperationEip712Hash, getUserOperationEip712Data, formatEip712SignaturesToUseroperationSignatureManual EIP-712 signing of one UserOperationTransactions and Signing
isDeployed, createAccountAddress, createInitializerCallDataCounterfactual address and deployment stateSetup, Owners and Modules
getSafeVersion, getFallbackHandler, isModuleEnabled, createDisableModuleMetaTransactionAccount state and modulesSetup, Owners and Modules
createAddOwnerWithThresholdMetaTransactions, createStandardAddOwnerWithThresholdMetaTransaction, createSwapOwnerMetaTransactions, createRemoveOwnerMetaTransactionAdd, swap and remove ownersSetup, Owners and Modules
verifyWebAuthnSignatureForMessageHashVerify a passkey signature, even before deploymentSetup, Owners and Modules

Methods​

initializeNewAccount​

Initializes a new Safe Unified Account from a list of owners. It computes the counterfactual account address and the factory data, but does not deploy anything: the account is deployed by its first UserOperation. Called on SafeMultiChainSigAccountV2, it uses the Safe L2 v1.5.0 singleton and returns a SafeMultiChainSigAccountV2 instance. Only needed while the account has not been deployed yet.

example.ts
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";

const ownerPublicAddress = "0xBdbc5FBC9cA8C3F514D073eC3de840Ac84FC6D31";
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);

console.log("Account address (sender): " + smartAccount.accountAddress);

Source code​

initializeNewAccount

createUserOperation​

Creates a UserOperation for multichain signing. This overrides the base SafeAccount method to always set isMultiChainSignature: true and use EntryPoint v0.9.

Determines the nonce, fetches gas prices, estimates gas limits, and returns a UserOperation to be signed. You can override any of these values using the overrides parameter.

example.ts
import {
SafeMultiChainSigAccountV1 as SafeAccount,
MetaTransaction,
} from "abstractionkit";

const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);

const transaction: MetaTransaction = {
to: "0xTargetAddress",
value: 0n,
data: "0x",
};

const userOperation = await smartAccount.createUserOperation(
[transaction],
"https://rpc-node-url",
"https://bundler-url",
);

Source code​

createUserOperation

estimateUserOperationGas​

Estimates gas limits for a multichain-signature UserOperation against a bundler, matching the estimation surface available on the other account classes. Returns a tuple of [preVerificationGas, verificationGasLimit, callGasLimit].

Usage​

import {
SafeMultiChainSigAccountV1 as SafeAccount,
MetaTransaction,
} from "abstractionkit";

const bundlerRpc = "https://api.candide.dev/public/v3/11155111";
const nodeRpcUrl = "https://rpc-node-url";

const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);

const transaction: MetaTransaction = {
to: "0xTargetAddress",
value: 0n,
data: "0x",
};

const userOperation = await smartAccount.createUserOperation(
[transaction],
nodeRpcUrl,
bundlerRpc,
);

const [preVerificationGas, verificationGasLimit, callGasLimit] =
await smartAccount.estimateUserOperationGas(userOperation, bundlerRpc);
keytypedescription
userOperationUserOperationV9The UserOperation to estimate gas for.
bundlerRpcstring | Transport | BundlerThe bundler RPC URL used to run eth_estimateUserOperationGas.
overrides?objectOptional overrides for the estimation, such as bundler state overrides and the dummy signatures used while estimating.
overrides?.stateOverrideSet?StateOverrideSetState overrides passed to the bundler during estimation.
overrides?.dummySignerSignaturePairs?SignerSignaturePair[]Dummy signer/signature pairs used as placeholders during estimation.
overrides?.expectedSigners?Signer[]The signers whose signatures will be produced at sign time. Used to build dummy signatures when dummySignerSignaturePairs is not provided.
overrides?.webAuthnSharedSigner?stringSpecify the WebAuthn shared signer. Defaults to the Safe Passkey module v0.2.1 value.
overrides?.webAuthnSignerFactory?stringSpecify the WebAuthn signer factory. Defaults to the Safe Passkey module v0.2.1 value.
overrides?.webAuthnSignerSingleton?stringSpecify the WebAuthn signer singleton. Defaults to the Safe Passkey module v0.2.1 value.
overrides?.webAuthnSignerProxyCreationCode?stringSpecify the WebAuthn signer proxy creation code. Defaults to the Safe Passkey module v0.2.1 value.
overrides?.eip7212WebAuthnPrecompileVerifier?stringSpecify the WebAuthn precompile verifier. Defaults to the RIP-7951 precompile.
overrides?.eip7212WebAuthnContractVerifier?stringSpecify the WebAuthn contract verifier. Defaults to the Daimo P256 verifier.

Source code​

estimateUserOperationGas

signUserOperation​

Signs a single UserOperation with one or more private keys. This overrides the base method to always encode the signature with the multichain scheme (isMultiChainSignature: true), which is how this account validates even single-chain UserOperations.

signUserOperation(
userOperation: UserOperationV9,
privateKeys: string[],
chainId: bigint,
options?: SafeSignatureOptions,
): string

Pass one private key per owner required by the threshold. options accepts the usual SafeSignatureOptions timing fields (validAfter, validUntil) and module address override; multiChainMerkleProof is rejected here, use signUserOperations for multi-op Merkle signatures.

example.ts
userOperation.signature = smartAccount.signUserOperation(
userOperation,
[ownerPrivateKey],
11155111n, // chainId
);

Source code​

signUserOperation

Manual EIP-712 signing for a single UserOperation​

SafeMultiChainSigAccountV1 also validates single-chain UserOperations through its multichain signature scheme. If you drive signTypedData yourself instead of using signUserOperationWithSigners, format the raw wallet signature with isMultiChainSignature: true.

example.ts
import {
EIP712_SAFE_OPERATION_PRIMARY_TYPE,
SafeMultiChainSigAccountV1 as SafeAccount,
} from "abstractionkit";
import type { TypedDataDefinition } from "viem";

const eip712Data = SafeAccount.getUserOperationEip712Data(
userOperation,
chainId,
);

const signature = await walletClient.signTypedData({
domain: eip712Data.domain,
types: eip712Data.types,
primaryType: EIP712_SAFE_OPERATION_PRIMARY_TYPE,
message: eip712Data.messageValue,
} as unknown as TypedDataDefinition);

userOperation.signature = SafeAccount.formatSignaturesToUseroperationSignature(
[{ signer: ownerAddress, signature }],
{ isMultiChainSignature: true },
);

Full example: eip-712-signing.ts.