Skip to main content

Safe Account Setup, Owners and Modules

Every AbstractionKit Safe account class has these methods: Safe Unified Account (SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2, the recommended classes), Safe Account V3 (SafeAccountV0_3_0) and Safe Account V2 (SafeAccountV0_2_0). Calldata, signing and sending methods are on Safe Account Transactions and Signing.

The examples import SafeMultiChainSigAccountV1 as SafeAccount, the recommended class for new Safes. Each method is called the same way on SafeMultiChainSigAccountV2, SafeAccountV0_3_0 and SafeAccountV0_2_0: change the import to your class. Where a class differs (UserOperation type, default addresses, example output), the section says so.

Methods at a Glance​

MethodSignatureReturns
isDeployed (static)isDeployed(accountAddress: string, nodeRpcUrl: string | Transport | JsonRpcNode)Promise<boolean>
createAccountAddress (static)createAccountAddress(owners: Signer[], overrides?: InitCodeOverrides)string
createInitializerCallData (static)createInitializerCallData(owners: Signer[], threshold: number, overrides?)string
getSafeVersiongetSafeVersion(nodeRpcUrl: string | Transport | JsonRpcNode)Promise<string>
getFallbackHandlergetFallbackHandler(nodeRpcUrl: string | Transport | JsonRpcNode)Promise<string>
isModuleEnabledisModuleEnabled(nodeRpcUrl: string | Transport | JsonRpcNode, moduleAddress: string)Promise<boolean>
createDisableModuleMetaTransactioncreateDisableModuleMetaTransaction(nodeRpcUrl, moduleToDisableAddress: string, accountAddress: string, overrides?: { prevModuleAddress?; modulesStart?; modulesPageSize? })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>
verifyWebAuthnSignatureForMessageHash (static)verifyWebAuthnSignatureForMessageHash(nodeRpcUrl, signer: WebauthnPublicKey, messageHash: string, signature: string, overrides?)Promise<boolean>

WebAuthn owners are derived with the Passkey module defaults of the class the method is called on: v0.2.1 on the Safe Unified Account classes. Per-call overrides win.

Account Address and State​

isDeployed​

Static method that checks whether a Safe account is already deployed on-chain. Use it to decide between connecting to an existing account (new SafeMultiChainSigAccountV1(address)) and initializing a counterfactual one (SafeAccountV0_3_0.initializeNewAccount(owners)). Once an account is deployed, the factory data carried by initializeNewAccount is no longer needed and including it would waste gas.

The same static method exists on every Safe class, for example SafeMultiChainSigAccountV1.isDeployed(...).

This only checks for non-empty bytecode at accountAddress. It does not verify that the deployed code is a Safe or that its on-chain configuration matches a given owner set.

Usage​

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

const accountAddress = "0x1a02592A3484c2077d2E5D24482497F85e1980C6";
const nodeRpcUrl = "https://ethereum-sepolia-rpc.publicnode.com";

const account = (await SafeAccount.isDeployed(accountAddress, nodeRpcUrl))
? new SafeAccount(accountAddress)
: SafeAccount.initializeNewAccount([ownerPublicAddress]);

Source code​

isDeployed

createAccountAddress​

Calculates the Account address from the initial owners

Usage​

In this example, we initiate a single owner account.

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

const ownerPublicAddress = "0xBdbc5FBC9cA8C3F514D073eC3de840Ac84FC6D31";
const safeAddress = SafeAccount.createAccountAddress(
[ownerPublicAddress],
);

console.log("Account address (sender): " + safeAddress);
Example Response
Account address (sender): 0x75cFD34827377361f08652A6528A76614c693C89

With SafeAccountV0_3_0, the same owner gives 0xd785Bb8A95A6a08aCE0Aa2e54aeE5cF04694b1db, and with SafeAccountV0_2_0, 0xb8741a449D50ed0Dcfe395287F85BE152884c8d9.

Each class derives the address from its own default Safe 4337 module, module setup contract and Passkey module defaults, so the same owners give a different address on each class. SafeMultiChainSigAccountV2 uses the Safe L2 v1.5.0 singleton by default; see V1 or V2.

Source code​

createInitializerCallData​

Creates the initializer calldata

Usage​

import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";

const initializeCallData = SafeAccount.createInitializerCallData(
[ownerPublicAddress], // owners
1, //threshold
);
console.log("initializeCallData: " + initializeCallData);
Example Response
initializeCallData: 0xb63e800d000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000002dd68b007b46fbe91b9a7c3eda5a7a1063cb5b47000000000000000000000000000000000000000000000000000000000000014000000000000000000000000022939e839e3c0f479b713eaf95e0df128554aead0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000bdbc5fbc9ca8c3f514d073ec3de840ac84fc6d3100000000000000000000000000000000000000000000000000000000000000648d0dc49f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000022939e839e3c0f479b713eaf95e0df128554aead00000000000000000000000000000000000000000000000000000000

With SafeAccountV0_3_0:

initializeCallData: 0xb63e800d000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000002dd68b007b46fbe91b9a7c3eda5a7a1063cb5b47000000000000000000000000000000000000000000000000000000000000014000000000000000000000000075cf11467937ce3f2f357ce24ffc3dbf8fd5c2260000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000bdbc5fbc9ca8c3f514d073ec3de840ac84fc6d3100000000000000000000000000000000000000000000000000000000000000648d0dc49f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000075cf11467937ce3f2f357ce24ffc3dbf8fd5c22600000000000000000000000000000000000000000000000000000000

With SafeAccountV0_2_0, which uses its own Safe 4337 module and module setup addresses:

initializeCallData: 0xb63e800d000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000008ecd4ec46d4d2a6b64fe960b3d64e8b94b2234eb0000000000000000000000000000000000000000000000000000000000000140000000000000000000000000a581c4a4db7175302464ff3c06380bc3270b40370000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000bdbc5fbc9ca8c3f514d073ec3de840ac84fc6d3100000000000000000000000000000000000000000000000000000000000000648d0dc49f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a581c4a4db7175302464ff3c06380bc3270b403700000000000000000000000000000000000000000000000000000000

Source code​

getSafeVersion​

Reads the Safe singleton version string via VERSION(), for example "1.4.1".

Usage​

import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";

const accountAddress = "0x1a02592A3484c2077d2E5D24482497F85e1980C6";
const nodeRpcUrl = "https://ethereum-sepolia-rpc.publicnode.com";

const smartAccount = new SafeAccount(accountAddress);
const version = await smartAccount.getSafeVersion(nodeRpcUrl);
keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe JSON-RPC API URL for the target chain.

Source code​

getSafeVersion

getFallbackHandler​

Reads the active ERC-4337 fallback handler (the 4337 module) currently set on the Safe.

Usage​

import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";

const accountAddress = "0x1a02592A3484c2077d2E5D24482497F85e1980C6";
const nodeRpcUrl = "https://ethereum-sepolia-rpc.publicnode.com";

const smartAccount = new SafeAccount(accountAddress);
const fallbackHandler = await smartAccount.getFallbackHandler(nodeRpcUrl);
keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe JSON-RPC API URL for the target chain.

Source code​

getFallbackHandler

Modules​

isModuleEnabled​

Checks if a specified module is enabled for a given Safe account. This function returns a boolean indicating the module's status.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe JSON-RPC API url for the target chain.
moduleAddressstringThe module address to check if enabled.

Source code​

isModuleEnabled

createDisableModuleMetaTransaction​

Creates a meta-transaction to disable a module from the Safe account. The function automatically fetches the previous module address in the linked list if not provided in the overrides. This function returns a promise that resolves to a meta-transaction object containing the necessary details for disabling the module.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe JSON-RPC API URL for the target chain to fetch the previous module address.
moduleToDisableAddressstringThe address of the module to be disabled.
accountAddressstringThe Safe account address for which to disable the module.
overridesobjectOptional overrides for the default values used in the transaction.
overrides.prevModuleAddressstringIf set, it will be used as the previous module address instead of fetching it.
overrides.modulesStartstringStarting address for the module pagination query.
overrides.modulesPageSizebigintPage size for the module pagination query.

Source code​

createDisableModuleMetaTransaction

Owners​

createAddOwnerWithThresholdMetaTransactions​

Builds the MetaTransactions needed to add a new owner (an ECDSA address or a WebAuthn public key) and set a new threshold. If the new owner is a WebAuthn signer whose verifier contract is not yet deployed, the returned list starts with a MetaTransaction that deploys the verifier, followed by the add-owner call, so it resolves to one or two MetaTransactions.

createAddOwnerWithThresholdMetaTransactions(
newOwner: Signer,
threshold: number,
overrides?: {
nodeRpcUrl?: string | Transport | JsonRpcNode;
eip7212WebAuthnPrecompileVerifier?: string;
eip7212WebAuthnContractVerifier?: string;
webAuthnSignerFactory?: string;
webAuthnSignerSingleton?: string;
webAuthnSignerProxyCreationCode?: string;
},
): Promise<MetaTransaction[]>

overrides.nodeRpcUrl is required when adding a WebAuthn owner, so the SDK can check whether the new owner's verifier is already deployed.

On SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2, a passkey owner is derived with the class's own Safe Passkey module v0.2.1 defaults, so the added owner is the signer the account signs with. Pass WebAuthn overrides only if you created the account with custom WebAuthn values.

example.ts
const newOwnerPublicAddress = "0xNewOwnerAddress";

const addOwnerMetaTransactions =
await smartAccount.createAddOwnerWithThresholdMetaTransactions(
newOwnerPublicAddress,
2, // new threshold
);

const userOperation = await smartAccount.createUserOperation(
addOwnerMetaTransactions,
nodeRpcUrl,
bundlerUrl,
);

Source code​

createAddOwnerWithThresholdMetaTransactions

createStandardAddOwnerWithThresholdMetaTransaction​

Builds the single standard addOwnerWithThreshold MetaTransaction for an owner public address. Unlike the plural variant above, it takes a plain address, performs no WebAuthn verifier handling, and returns synchronously.

createStandardAddOwnerWithThresholdMetaTransaction(
newOwner: string,
threshold: number,
): MetaTransaction
example.ts
const addOwnerMetaTransaction =
smartAccount.createStandardAddOwnerWithThresholdMetaTransaction(
"0xNewOwnerAddress",
2, // new threshold
);

Source code​

createStandardAddOwnerWithThresholdMetaTransaction

createSwapOwnerMetaTransactions​

Creates a meta-transaction to swap an owner in the Safe account. If a new owner verifier is not already deployed, it will deploy one and fetch the previous owner automatically. This function returns a promise that resolves to a list of meta-transactions containing the necessary details for the swap and deployment.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe JSON-RPC API URL for the target chain to fetch the previous owner.
newOwnerobjectThe public address of the new owner to be added.
newOwner.SignerECDSAPublicAddress | WebauthnPublicKeySigner type which can be either an ECDSA public address or a Webauthn public key
oldOwnerSignerThe public address of the owner to be replaced.
overridesobjectOverrides for the default values used in the transaction.
overrides.prevOwnerstringIf set, it will be used as the previous owner instead of fetching it.
overrides.eip7212WebAuthnPrecompileVerifierstringAddress for the EIP-7212 WebAuthn precompile verifier.
overrides.eip7212WebAuthnContractVerifierstringAddress for the EIP-7212 WebAuthn contract verifier.
overrides.webAuthnSignerFactorystringAddress for the WebAuthn signer factory.
overrides.webAuthnSignerSingletonstringAddress for the WebAuthn signer singleton.
overrides.webAuthnSignerProxyCreationCodestringCreation code of the WebAuthn signer proxy.

Source code​

createSwapOwnerMetaTransactions

createRemoveOwnerMetaTransaction​

Creates a meta-transaction to remove an owner from the Safe account, fetching the previous owner if not provided. This function returns a promise that resolves to a meta-transaction object containing the necessary details for the removal.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe JSON-RPC API URL for the target chain to fetch the previous owner.
ownerToDeleteobjectThe public address of the owner to be deleted.
ownerToDelete.SignerECDSAPublicAddress | WebauthnPublicKeySigner type which can be either an ECDSA public address or a Webauthn public key
thresholdnumberThe new threshold value for owner confirmations after removal.
overridesobjectOptional Overrides for the default values used in the transaction.
overrides.prevOwnerstringIf set, it will be used as the previous owner instead of fetching it.
overrides.eip7212WebAuthnPrecompileVerifierstringAddress for the EIP-7212 WebAuthn precompile verifier.
overrides.eip7212WebAuthnContractVerifierstringAddress for the EIP-7212 WebAuthn contract verifier.
overrides.webAuthnSignerFactorystringAddress for the WebAuthn signer factory.
overrides.webAuthnSignerSingletonstringAddress for the WebAuthn signer singleton.
overrides.webAuthnSignerProxyCreationCodestringCreation code of the WebAuthn signer proxy.

Source code​

createRemoveOwnerMetaTransaction

verifyWebAuthnSignatureForMessageHash​

A static method that verifies a webAuthn signed hash message for Passkeys, and can be also used even if the safe account hasn't been deployed yet.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe JSON-RPC API url for the target chain.
signerobjectThe x and y coordinates of the webAuthn public key
signer.xbigintThe x coordinate of the webAuthn public key
signer.ybigintThe y coordinate of the webAuthn public key
messageHashstringThe 0x-prefixed 32-byte hash of the message to verify
signaturestringThe signed message
overridesobjectOptional overrides for webAuthn verify signature message
overrides.webAuthnSignerSingletonstringSpecify the WebAuthn signer singleton
overrides.eip7212WebAuthnPrecompileVerifierstringSpecify the EIP-7212 WebAuthn precompile verifier
overrides.eip7212WebAuthnContractVerifierstringSpecify the EIP-7212 WebAuthn contract verifier

On the Safe Unified Account classes, the default verifier addresses come from the class's Safe Passkey module v0.2.1 defaults.

Source code​