Safe Account
The SafeAccount uses the original Safe Singleton and adds ERC-4337 functionality using a module/fallback handler. For new integrations, use Safe Unified Account (SafeMultiChainSigAccountV1, or SafeMultiChainSigAccountV2 for Safe v1.5.0) on EntryPoint v0.9; use the V2/V3 classes below for legacy EntryPoint v0.6/v0.7 compatibility.
- The V2 contracts, or
SafeAccountV0_2_0in AbstractionKit, support EntryPoint v0.6. - The V3 contracts, or
SafeAccountV0_3_0in AbstractionKit, support EntryPoint v0.7.
The contracts were developed by the Safe Team and audited by OpenZeppelin & Ackee Blockchain.
Methods at a Glance
Every Safe class shares these methods. Each is documented once, on Safe Account Transactions and Signing or Safe Account Setup, Owners and Modules, with notes where a class differs. userOperation is a UserOperationV9 on the Safe Unified Account, UserOperationV7 on SafeAccountV0_3_0 and UserOperationV6 on SafeAccountV0_2_0.
| Method | Signature | Returns |
|---|---|---|
| sendUserOperation | sendUserOperation(userOperation, bundlerRpc: string | Transport | Bundler) | Promise<SendUseroperationResponse> |
| signUserOperationWithSigners | signUserOperationWithSigners(userOperation, signers: ReadonlyArray<ExternalSigner>, chainId: bigint, options?: SafeSignatureOptions) | Promise<string> |
| createAccountCallDataSingleTransaction | createAccountCallDataSingleTransaction(metaTransaction: MetaTransaction, overrides?) | string |
| createAccountCallDataBatchTransactions | createAccountCallDataBatchTransactions(metaTransactions: MetaTransaction[], overrides?) | string |
| getUserOperationEip712Hash | getUserOperationEip712Hash(useroperation, chainId: bigint, overrides?) | string |
| getUserOperationEip712Data | getUserOperationEip712Data(useroperation, chainId: bigint, overrides?) | { domain; types; messageValue } |
| formatEip712SignaturesToUseroperationSignature | formatEip712SignaturesToUseroperationSignature(signersAddresses: string[], signatures: string[], overrides?) | string |
| isDeployed | isDeployed(accountAddress: string, nodeRpcUrl: string | Transport | JsonRpcNode) | Promise<boolean> |
| createAccountAddress | createAccountAddress(owners: Signer[], overrides?: InitCodeOverrides) | string |
| createInitializerCallData | createInitializerCallData(owners: Signer[], threshold: number, overrides?) | string |
| getSafeVersion | getSafeVersion(nodeRpcUrl) | Promise<string> |
| getFallbackHandler | getFallbackHandler(nodeRpcUrl) | Promise<string> |
| isModuleEnabled | isModuleEnabled(nodeRpcUrl, moduleAddress: string) | Promise<boolean> |
| createDisableModuleMetaTransaction | createDisableModuleMetaTransaction(nodeRpcUrl, moduleToDisableAddress: string, accountAddress: string, overrides?) | Promise<MetaTransaction> |
| createAddOwnerWithThresholdMetaTransactions | createAddOwnerWithThresholdMetaTransactions(newOwner: Signer, threshold: number, overrides?) | Promise<MetaTransaction[]> |
| createStandardAddOwnerWithThresholdMetaTransaction | createStandardAddOwnerWithThresholdMetaTransaction(newOwner: string, threshold: number) | MetaTransaction |
| createSwapOwnerMetaTransactions | createSwapOwnerMetaTransactions(nodeRpcUrl, newOwner: Signer, oldOwner: Signer, overrides?) | Promise<MetaTransaction[]> |
| createRemoveOwnerMetaTransaction | createRemoveOwnerMetaTransaction(nodeRpcUrl, ownerToDelete: Signer, threshold: number, overrides?) | Promise<MetaTransaction> |
| verifyWebAuthnSignatureForMessageHash | verifyWebAuthnSignatureForMessageHash(nodeRpcUrl, signer: WebauthnPublicKey, messageHash: string, signature: string, overrides?) | Promise<boolean> |
Class-specific methods (initializeNewAccount, createUserOperation, estimateUserOperationGas, signUserOperation, the migration helpers) are on each class page: Safe Unified Account, with its multichain signing methods on Safe Unified Account Multichain Signing, Safe Account V3 and Safe Account V2.
Audits
To learn more about the contracts, visit the repository of Safe ERC-4337 Module.
Import
Recommended for EntryPoint v0.9
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
// or, for new accounts on the Safe v1.5.0 singleton:
// import { SafeMultiChainSigAccountV2 as SafeAccount } from "abstractionkit";
SafeMultiChainSigAccountV2 is not related to the "V2 contracts" below: it is the Safe Unified Account on the Safe L2 v1.5.0 singleton. See V1 or V2.
V3 for EntryPoint v0.7
import { SafeAccountV0_3_0 as SafeAccount } from "abstractionkit";
V2 for EntryPoint v0.6
import { SafeAccountV0_2_0 as SafeAccount } from "abstractionkit";
How to Use
AbstractionKit classes are designed to support the same methods across all versions, ensuring compatibility within the essential classes. This allows developers to move between Safe V2, Safe V3 and the Safe Unified Account seamlessly without breaking functionality or requiring significant code changes. Targeting a different EntryPoint is a change of account class rather than a separate integration. See Compatibility with Safe Account V3. Each version derives a different counterfactual address for the same owner, so a new account is a different account under each class. An already-deployed Safe keeps the address it has; it needs only its module and fallback handler migrated before another version's class can operate on it.
To initialize a new Safe Account and calculate its address:
const ownerPublicAddress = "0xBdbc5FBC9cA8C3F514D073eC3de840Ac84FC6D31"; // Safe owner pub address
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
const accountAddress = smartAccount.accountAddress;
Compatibility with Safe Account V3
SafeMultiChainSigAccountV1 is API-compatible with SafeAccountV0_3_0. Both extend the same SafeAccount base and expose the same methods with the same signatures, so moving to EntryPoint v0.9 is a change of account class, not a separate integration:
| Method | SafeAccountV0_3_0 | SafeMultiChainSigAccountV1 |
|---|---|---|
createAccountAddress(owners, overrides) | ✅ | ✅ |
initializeNewAccount(owners, overrides) | ✅ | ✅ |
isDeployed(address, rpc) | ✅ | ✅ |
createUserOperation(txs, nodeRpc, bundlerRpc, overrides) | ✅ | ✅ |
estimateUserOperationGas(userOp, bundlerRpc, overrides) | ✅ | ✅ |
signUserOperation(userOp, privateKeys, chainId, options) | ✅ | ✅ |
signUserOperationWithSigners(userOp, signers, chainId, options) | ✅ | ✅ |
sendUserOperation(userOp, bundlerRpc) | ✅ | ✅ |
Both classes take the same InitCodeOverrides shape, so an integration that already threads entrypointAddress, safe4337ModuleAddress, safeModuleSetupAddress, safeAccountSingleton, safeAccountFactoryAddress and c2Nonce through its config needs no new plumbing.
The multichain APIs (signUserOperations, signUserOperationsWithSigners, the Merkle-root EIP-712 helpers and the WebAuthn verifier helpers) are additional methods. Opt into them for chain abstraction, or ignore them and the account behaves as a single-chain Safe.
A few differences to be aware of when migrating:
-
New accounts get a different address. A different Safe module and EntryPoint derive a different counterfactual address for the same owner, so
SafeMultiChainSigAccountV1andSafeAccountV0_3_0never refer to the same undeployed account. -
Deployed accounts must be migrated first. Attaching
SafeMultiChainSigAccountV1to a Safe that was deployed throughSafeAccountV0_3_0is not sufficient. Two pieces of Safe configuration have to change first: the v0.9 module must be enabled on the Safe, and the Safe's fallback handler must be updated to point at it. Until both land, the account cannot be used on EntryPoint v0.9 and UserOperations sent to it will fail. Build the batch withcreateMigrateToSafeMultiChainSigAccountMetaTransactionsand send it as a UserOperation from the v0.7 account itself; once it lands, attach the same address toSafeMultiChainSigAccountV1, or toSafeMultiChainSigAccountV2if the Safe runs the v1.5.0 singleton. -
Passkey owners keep their v0.2.0 signer. Migration does not touch the owners, so a passkey owner of a v0.7 Safe is still the signer derived with the Safe Passkey module v0.2.0 defaults, while V1 and V2 default to v0.2.1. Pass the v0.2.0 values as
createUserOperationoverrides and build the signer withaccountClass: SafeAccountV0_3_0, or the SDK derives an address that is not an owner:const legacyWebAuthn = {webAuthnSharedSigner: SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_SHARED_SIGNER,webAuthnSignerFactory: SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_SIGNER_FACTORY,webAuthnSignerSingleton: SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_SIGNER_SINGLETON,webAuthnSignerProxyCreationCode: SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_SIGNER_PROXY_CREATION_CODE,eip7212WebAuthnPrecompileVerifier: SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_PRECOMPILE,eip7212WebAuthnContractVerifier: SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_CONTRACT_VERIFIER,};const userOperation = await smartAccount.createUserOperation(transactions, nodeRpcUrl, bundlerUrl, {expectedSigners: [publicKey],...legacyWebAuthn,});const signer = fromSafeWebauthn({publicKey,isInit: userOperation.factory != null, // the v0.9 nonce restarts at 0, so don't use it hereaccountClass: SafeAccountV0_3_0,getAssertion,});See the migration e2e test.
-
The UserOperation type is
UserOperationV9. It adds a nullableeip7702Authfield to the v0.7 shape; every other field, including the gas fields and the paymaster and factory fields, is unchanged. -
Signatures always use the multichain encoding.
isMultiChainSignatureis set for you, including on single-chain UserOperations: the single-op path signs the leaf SafeOp hash directly rather than a Merkle root. This is handled inside AbstractionKit; you only need it when formatting a signature yourself. -
Your bundler and paymaster must serve EntryPoint v0.9. Check that the v0.9 EntryPoint and the Safe multichain signature module are deployed on your target chains before predicting addresses for them.
Safe Unified Account
Recommended Safe account for EntryPoint v0.9, single-chain and multichain
Safe Unified Account Multichain Signing
Sign UserOperations for several chains with one signature
Safe Account Transactions and Signing
Shared calldata, signing and sending methods for every Safe class
Safe Account Setup, Owners and Modules
Shared address, owner, module and account-state methods for every Safe class
Safe Account V3
Reference functions for Safe Account V3 with EntryPoint V7
Safe Account V2
Reference functions for Safe Account V2 with EntryPoint V6