Skip to main content

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_0 in AbstractionKit, support EntryPoint v0.6.
  • The V3 contracts, or SafeAccountV0_3_0 in 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.

MethodSignatureReturns
sendUserOperationsendUserOperation(userOperation, bundlerRpc: string | Transport | Bundler)Promise<SendUseroperationResponse>
signUserOperationWithSignerssignUserOperationWithSigners(userOperation, signers: ReadonlyArray<ExternalSigner>, chainId: bigint, options?: SafeSignatureOptions)Promise<string>
createAccountCallDataSingleTransactioncreateAccountCallDataSingleTransaction(metaTransaction: MetaTransaction, overrides?)string
createAccountCallDataBatchTransactionscreateAccountCallDataBatchTransactions(metaTransactions: MetaTransaction[], overrides?)string
getUserOperationEip712HashgetUserOperationEip712Hash(useroperation, chainId: bigint, overrides?)string
getUserOperationEip712DatagetUserOperationEip712Data(useroperation, chainId: bigint, overrides?){ domain; types; messageValue }
formatEip712SignaturesToUseroperationSignatureformatEip712SignaturesToUseroperationSignature(signersAddresses: string[], signatures: string[], overrides?)string
isDeployedisDeployed(accountAddress: string, nodeRpcUrl: string | Transport | JsonRpcNode)Promise<boolean>
createAccountAddresscreateAccountAddress(owners: Signer[], overrides?: InitCodeOverrides)string
createInitializerCallDatacreateInitializerCallData(owners: Signer[], threshold: number, overrides?)string
getSafeVersiongetSafeVersion(nodeRpcUrl)Promise<string>
getFallbackHandlergetFallbackHandler(nodeRpcUrl)Promise<string>
isModuleEnabledisModuleEnabled(nodeRpcUrl, moduleAddress: string)Promise<boolean>
createDisableModuleMetaTransactioncreateDisableModuleMetaTransaction(nodeRpcUrl, moduleToDisableAddress: string, accountAddress: string, overrides?)Promise<MetaTransaction>
createAddOwnerWithThresholdMetaTransactionscreateAddOwnerWithThresholdMetaTransactions(newOwner: Signer, threshold: number, overrides?)Promise<MetaTransaction[]>
createStandardAddOwnerWithThresholdMetaTransactioncreateStandardAddOwnerWithThresholdMetaTransaction(newOwner: string, threshold: number)MetaTransaction
createSwapOwnerMetaTransactionscreateSwapOwnerMetaTransactions(nodeRpcUrl, newOwner: Signer, oldOwner: Signer, overrides?)Promise<MetaTransaction[]>
createRemoveOwnerMetaTransactioncreateRemoveOwnerMetaTransaction(nodeRpcUrl, ownerToDelete: Signer, threshold: number, overrides?)Promise<MetaTransaction>
verifyWebAuthnSignatureForMessageHashverifyWebAuthnSignatureForMessageHash(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​

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:

MethodSafeAccountV0_3_0SafeMultiChainSigAccountV1
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 SafeMultiChainSigAccountV1 and SafeAccountV0_3_0 never refer to the same undeployed account.

  • Deployed accounts must be migrated first. Attaching SafeMultiChainSigAccountV1 to a Safe that was deployed through SafeAccountV0_3_0 is 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 with createMigrateToSafeMultiChainSigAccountMetaTransactions and send it as a UserOperation from the v0.7 account itself; once it lands, attach the same address to SafeMultiChainSigAccountV1, or to SafeMultiChainSigAccountV2 if 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 createUserOperation overrides and build the signer with accountClass: 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 here
    accountClass: SafeAccountV0_3_0,
    getAssertion,
    });

    See the migration e2e test.

  • The UserOperation type is UserOperationV9. It adds a nullable eip7702Auth field 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. isMultiChainSignature is 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.