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:
| Class | Safe singleton | Use it for |
|---|---|---|
SafeMultiChainSigAccountV1 | Safe L2 v1.4.1 | Existing V1 accounts and new accounts on Safe v1.4.1 |
SafeMultiChainSigAccountV2 | Safe L2 v1.5.0 | New 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)andnew 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. UseSafeMultiChainSigAccountV2for 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.
| Method | Signature | Returns |
|---|---|---|
| constructor | new SafeMultiChainSigAccountV1(accountAddress: string, overrides?: { safe4337ModuleAddress?; entrypointAddress?; onChainIdentifierParams?; onChainIdentifier?; safeAccountSingleton? }) | SafeMultiChainSigAccountV1 |
| initializeNewAccount (static) | initializeNewAccount(owners: Signer[], overrides?: InitCodeOverrides) | InstanceType<T> |
| createUserOperation | createUserOperation(transactions: MetaTransaction[], providerRpc?: string | Transport | JsonRpcNode, bundlerRpc?: string | Transport | Bundler, overrides?: CreateUserOperationV9Overrides) | Promise<UserOperationV9> |
| estimateUserOperationGas | estimateUserOperationGas(userOperation: UserOperationV9, bundlerRpc: string | Transport | Bundler, overrides?) | Promise<[bigint, bigint, bigint]> |
| signUserOperation | signUserOperation(userOperation: UserOperationV9, privateKeys: string[], chainId: bigint, options?: SafeSignatureOptions) | string |
| 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[] |
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.
| Method | Purpose | Documented on |
|---|---|---|
| sendUserOperation | Send a signed UserOperation to the bundler | Transactions and Signing |
| signUserOperationWithSigners | Sign one UserOperation with ExternalSigners (viem, ethers, passkeys, HSMs) | Transactions and Signing |
| createAccountCallDataSingleTransaction, createAccountCallDataBatchTransactions | Encode MetaTransactions as account calldata | Transactions and Signing |
| getUserOperationEip712Hash, getUserOperationEip712Data, formatEip712SignaturesToUseroperationSignature | Manual EIP-712 signing of one UserOperation | Transactions and Signing |
| isDeployed, createAccountAddress, createInitializerCallData | Counterfactual address and deployment state | Setup, Owners and Modules |
| getSafeVersion, getFallbackHandler, isModuleEnabled, createDisableModuleMetaTransaction | Account state and modules | Setup, Owners and Modules |
| createAddOwnerWithThresholdMetaTransactions, createStandardAddOwnerWithThresholdMetaTransaction, createSwapOwnerMetaTransactions, createRemoveOwnerMetaTransaction | Add, swap and remove owners | Setup, Owners and Modules |
| verifyWebAuthnSignatureForMessageHash | Verify a passkey signature, even before deployment | Setup, 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
- Param Types
- Return Type
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
const ownerPublicAddress = "0xBdbc5FBC9cA8C3F514D073eC3de840Ac84FC6D31";
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
console.log("Account address (sender): " + smartAccount.accountAddress);
| key | type | description |
|---|---|---|
owners[] | object | Pass the owner(s) address(es) of the account. It can be a single owner account, a multi-sig, or a WebAuthn |
owners[].Signer | ECDSAPublicAddress | WebauthnPublicKey | Signer type which can be either an ECDSA public address or a Webauthn public key |
initCodeOverrides? | object | Override values to change the initialization default values |
initCodeOverrides?.threshold? | number | Signature threshold, defines how many signatures are required. Default is 1. |
initCodeOverrides?.c2Nonce? | bigint | Create2 nonce used to generate different sender addresses from the same owners. Default is 0. |
initCodeOverrides?.entrypointAddress? | string | Address of the entry point for transactions or contracts. |
initCodeOverrides?.safe4337ModuleAddress? | string | Address of the Safe 4337 module. |
initCodeOverrides?.safeModuleSetupAddress? | string | Address used for setting up the Safe module. |
initCodeOverrides?.safeAccountSingleton? | SafeAccountSingleton | Safe singleton address and init hash. Default is Safe L2 v1.4.1 ("0x29fcB43b46531BcA003ddC8FCB67FFE91900C762"), or Safe L2 v1.5.0 ("0xEdd160fEBBD92E350D4D398fb636302fccd67C7e") for SafeMultiChainSigAccountV2. Pass the exported Safe_L2_V1_4_1 or Safe_L2_V1_5_0 to pick one explicitly. |
initCodeOverrides?.safeAccountFactoryAddress? | string | Address of the Safe Factory. Default is "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67". |
initCodeOverrides?.multisendContractAddress? | string | Address of the Safe MultiSend contract. Default is "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526". |
initCodeOverrides?.webAuthnSharedSigner? | string | Shared signer used for WebAuthn-based authentication. |
initCodeOverrides?.eip7212WebAuthnPrecompileVerifierForSharedSigner? | string | Verifier contract for WebAuthn precompile, related to the shared signer. |
initCodeOverrides?.eip7212WebAuthnContractVerifierForSharedSigner? | string | Contract verifier for WebAuthn-based shared signer, compliant with EIP-7212. |
initCodeOverrides?.onChainIdentifierParams? | OnChainIdentifierParamsType | Parameters for on-chain identifier tracking. |
initCodeOverrides?.onChainIdentifier? | string | Pre-computed on-chain identifier string. |
| key | type | description |
|---|---|---|
ECDSAPublicAddress | string | Public address of an ECDSA (EOA) owner |
WebauthnPublicKey
| key | type | description |
|---|---|---|
x | bigint | The x coordinate of the webAuthn public key |
y | bigint | The y coordinate of the webAuthn public key |
| key | type | description |
|---|---|---|
SafeAccount class | SafeMultiChainSigAccountV1 | SafeMultiChainSigAccountV2 | An instance of the class it was called on (V1 or V2), with the initialization parameters |
Source code
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
- Param Types
- Return Type
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",
);
| Param Name | Param Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Transactions | MetaTransaction[]
| MetaTransaction is the type of a transaction to construct a Safe operation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Provider RPC | string | Transport | JsonRpcNode | The node URL. It is used to fetch the current nonce and fetch gas prices | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bundler URL | string | Transport | Bundler | The Bundler URL. It is used to fetch the gas limits | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Overrides | CreateUserOperationV9Overrides, optional object
| CreateUserOperationV9Overrides allows you to override any of the default parameters for the user operation. It has the same fields as CreateUserOperationV7Overrides. |
| Param Name | Param Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| UserOperation | Promise<UserOperationV9>
| Returns an unsigned UserOperation for EntryPoint v0.9. |
Source code
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);
- Param Types
- Return Types
| key | type | description |
|---|---|---|
userOperation | UserOperationV9 | The UserOperation to estimate gas for. |
bundlerRpc | string | Transport | Bundler | The bundler RPC URL used to run eth_estimateUserOperationGas. |
overrides? | object | Optional overrides for the estimation, such as bundler state overrides and the dummy signatures used while estimating. |
overrides?.stateOverrideSet? | StateOverrideSet | State 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? | string | Specify the WebAuthn shared signer. Defaults to the Safe Passkey module v0.2.1 value. |
overrides?.webAuthnSignerFactory? | string | Specify the WebAuthn signer factory. Defaults to the Safe Passkey module v0.2.1 value. |
overrides?.webAuthnSignerSingleton? | string | Specify the WebAuthn signer singleton. Defaults to the Safe Passkey module v0.2.1 value. |
overrides?.webAuthnSignerProxyCreationCode? | string | Specify the WebAuthn signer proxy creation code. Defaults to the Safe Passkey module v0.2.1 value. |
overrides?.eip7212WebAuthnPrecompileVerifier? | string | Specify the WebAuthn precompile verifier. Defaults to the RIP-7951 precompile. |
overrides?.eip7212WebAuthnContractVerifier? | string | Specify the WebAuthn contract verifier. Defaults to the Daimo P256 verifier. |
| key | type | description |
|---|---|---|
[preVerificationGas, verificationGasLimit, callGasLimit] | Promise<[bigint, bigint, bigint]> | Resolves to a tuple of the estimated preVerificationGas, verificationGasLimit, and callGasLimit. |
Source code
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.
userOperation.signature = smartAccount.signUserOperation(
userOperation,
[ownerPrivateKey],
11155111n, // chainId
);
Source code
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.
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.