Safe Account Transactions and Signing
Every AbstractionKit Safe account class inherits these methods from the base SafeAccount class: Safe Unified Account (SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2, the recommended classes), Safe Account V3 (SafeAccountV0_3_0) and Safe Account V2 (SafeAccountV0_2_0). Building, estimating and signing with private keys are class-specific and documented on each class page. Owner, module and address methods are on Safe Account Setup, Owners and Modules.
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
| Method | Signature | Returns |
|---|---|---|
| sendUserOperation | sendUserOperation(userOperation: UserOperationV6 | UserOperationV7 | UserOperationV9, bundlerRpc: string | Transport | Bundler) | Promise<SendUseroperationResponse> |
| signUserOperationWithSigners | signUserOperationWithSigners(userOperation, signers: ReadonlyArray<ExternalSigner>, chainId: bigint, options?: SafeSignatureOptions) | Promise<string> |
| createAccountCallDataSingleTransaction (static) | createAccountCallDataSingleTransaction(metaTransaction: MetaTransaction, overrides?: { safeModuleExecutorFunctionSelector? }) | string |
| createAccountCallDataBatchTransactions (static) | createAccountCallDataBatchTransactions(metaTransactions: MetaTransaction[], overrides?: { safeModuleExecutorFunctionSelector?; multisendContractAddress? }) | string |
| getUserOperationEip712Hash (static) | getUserOperationEip712Hash(useroperation, chainId: bigint, overrides?: { validAfter?; validUntil?; entrypointAddress?; safe4337ModuleAddress? }) | string |
| getUserOperationEip712Data (static) | getUserOperationEip712Data(useroperation, chainId: bigint, overrides?: { validAfter?; validUntil?; entrypointAddress?; safe4337ModuleAddress? }) | { domain; types; messageValue } |
| formatEip712SignaturesToUseroperationSignature (static) | formatEip712SignaturesToUseroperationSignature(signersAddresses: string[], signatures: string[], overrides?: { validAfter?; validUntil?; isMultiChainSignature?; merkleProof? }) | string |
useroperation is UserOperationV9 on the Safe Unified Account, UserOperationV7 on SafeAccountV0_3_0 and UserOperationV6 on SafeAccountV0_2_0.
Methods
sendUserOperation
This method sends the UserOperation to the bundler to be executed on-chain. It returns a promise SendUseroperationResponse object to confirm the on-chain inclusion of the UserOperation.
- example.ts
- Param Types
- Return Type
const sendUserOperationResponse = await smartAccount.sendUserOperation(userOperation, bundlerUrl)
console.log("sendUserOperationResponse: ", sendUserOperationResponse);
console.log("UserOperation sent. Waiting to be included...");
const receipt = await sendUserOperationResponse.included()
console.log("receipt: ", receipt);
| key | type | description |
|---|---|---|
userOperation | UserOperationV7 | userOperation to send |
bundlerRpc | string | Transport | Bundler | bundler rpc to send userOperation |
UserOperationV7
| key | type | description |
|---|---|---|
sender | string | The account making the operation |
nonce | bigint | Anti-replay parameter (see “Semi-abstracted Nonce Support” ) |
factory | string | null | account factory, only for new accounts (null if the account already exists) |
factoryData | string | null | data for account factory (null if the account already exists) |
callData | string | The data to pass to the sender during the main execution call |
callGasLimit | bigint | The amount of gas to allocate the main execution call |
verificationGasLimit | bigint | The amount of gas to allocate for the verification step |
preVerificationGas | bigint | Extra gas to pay the bundler |
maxFeePerGas | bigint | Maximum fee per gas (similar to EIP-1559 max_fee_per_gas) |
maxPriorityFeePerGas | bigint | Maximum priority fee per gas (similar to EIP-1559 max_priority_fee_per_gas) |
paymaster | string | null | Address of paymaster contract (null if account pays for itself) |
paymasterVerificationGasLimit | bigint | null | The amount of gas to allocate for the paymaster verification step |
paymasterPostOpGasLimit | bigint | null | The amount of gas to allocate for the paymaster post-operation code |
paymasterData | string | null | Data for paymaster (null if no paymaster) |
signature | string | Data passed into the account to verify authorization |
| key | type | description |
|---|---|---|
userOperationHash | string | The hash over the userOp (except signature), entryPoint and chainId |
bundler | Bundler | The Bundler class |
entrypointAddress | string | The entrypoint address where the useroperation got executed |
included() | Promise<UserOperationReceiptResult> | Waits for the user operation to be included onchain and returns the user operation receipt. Takes optional timeoutInSeconds (default 180) and requestIntervalInSeconds (default 2), and throws an AbstractionKitError with code TIMEOUT if the receipt is not found in time. A poll that fails with a transient error is retried, and the last failure becomes the cause of the TIMEOUT error |
UserOperationReceiptResult
| key | type | description |
|---|---|---|
userOpHash | string | The hash of the user operation. |
entryPoint | string | The address of the entry point contract that processed the operation. |
sender | string | The address of the sender of the user operation. |
nonce | bigint | The nonce of the user operation. |
paymaster | string | The address of the paymaster that paid for the gas of the user operation. |
actualGasCost | bigint | The actual gas cost incurred for executing the user operation. |
actualGasUsed | bigint | The actual amount of gas used for the user operation. |
success | boolean | Indicates whether the user operation was successful. |
logs | Log[] | The logs produced during the execution of the user operation. |
receipt | object | The detailed receipt of the user operation. |
receipt.blockHash | string | The hash of the block in which the transaction was included. |
receipt.blockNumber | bigint | The number of the block in which the transaction was included. |
receipt.from | string | The address that initiated the transaction. |
receipt.cumulativeGasUsed | bigint | The total amount of gas used in the block up to and including this transaction. |
receipt.gasUsed | bigint | The amount of gas used by this transaction. |
receipt.logs | Log[] | Logs generated by the transaction. |
receipt.logsBloom | string | The bloom filter for the logs generated by the transaction. |
receipt.transactionHash | string | The unique hash of the transaction. |
receipt.transactionIndex | bigint | The index of the transaction within the block. |
receipt.effectiveGasPrice | bigint | The effective gas price for the transaction. This field is optional and may not be present in all receipts. |
Example Response
sendUserOperationResponse: SendUseroperationResponse {
userOperationHash: '0xbd2cf2185876fbc6eccfdcb9e7a6d606f1032fd0f38b3a3c7ddf7d59d605f0e4',
bundler: Bundler {
transport: HttpTransport {
nextId: 2,
url: 'https://api.candide.dev/public/v3/11155111',
options: {}
},
outbound: { request: [Function: request] }
},
entrypointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032'
}
UserOperation sent. Waiting to be included...
receipt: {
userOpHash: '0xbd2cf2185876fbc6eccfdcb9e7a6d606f1032fd0f38b3a3c7ddf7d59d605f0e4',
entryPoint: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
sender: '0x4604a50478f900dbbb6dc5b3f2fd4d498bc8939d',
nonce: 0n,
paymaster: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
actualGasCost: 161556241n,
actualGasUsed: 2098133n,
success: true,
logs: [
{
address: '0x0000000071727de22e5e9d8baf0edac6f37da032',
topics: [Array],
data: '0x000000000000000000000000000000000000000000000000000000000000000000000000...',
blockHash: '0x634d29185efba9d6ef6f98a6c547a50b71c021c3a78c389828970ca772181478',
blockNumber: '0xb8da33',
blockTimestamp: '0x6af4e230',
transactionHash: '0x3a69747ddf810c6f908036782319b75e24bd535bb4b9f880feecdedd301a075b',
transactionIndex: '0xb',
logIndex: '0x17',
removed: false
}
],
receipt: {
blockHash: '0x634d29185efba9d6ef6f98a6c547a50b71c021c3a78c389828970ca772181478',
blockNumber: 12114483n,
from: '0x3cfdc212769c890907bce93d3d8c2c53de6a7a89',
cumulativeGasUsed: 7840335n,
gasUsed: 1974796n,
logs: [
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
logsBloom: '0x000004000018100000000001000000008000001000000000000000000200000000080000...',
transactionHash: '0x3a69747ddf810c6f908036782319b75e24bd535bb4b9f880feecdedd301a075b',
transactionIndex: 11n,
effectiveGasPrice: 171n
}
}
On SafeAccountV0_2_0 (EntryPoint v0.6), userOperation is a UserOperationV6 (see Safe Account V2 for its fields), and entrypointAddress in the response and entryPoint in the receipt are the EntryPoint v0.6 address 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789. On the Safe Unified Account (SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2, EntryPoint v0.9), userOperation is a UserOperationV9 (see Safe Unified Account).
To send from a fresh instance, attach the account by its address:
const account = new SafeAccount(userOperation.sender);
const response = await account.sendUserOperation(userOperation, bundlerUrl);
const receipt = await response.included();
Source code
signUserOperationWithSigners
Signs a UserOperation using one or more ExternalSigners instead of raw private keys. Integrates viem, ethers, hardware wallets, HSMs, MPC services, and WebAuthn through the same API.
- viem example
- ethers example
import { fromViem } from "abstractionkit";
import { privateKeyToAccount } from "viem/accounts";
const viemAccount = privateKeyToAccount("0x...");
userOperation.signature = await smartAccount.signUserOperationWithSigners(
userOperation,
[fromViem(viemAccount)],
chainId,
);
import { fromEthersWallet } from "abstractionkit";
import { Wallet } from "ethers";
const wallet = new Wallet("0x...");
userOperation.signature = await smartAccount.signUserOperationWithSigners(
userOperation,
[fromEthersWallet(wallet)],
chainId,
);
See External Signers for the full list of adapters and custom-signer integrations.
On SafeAccountV0_2_0 (EntryPoint v0.6), userOperation is a UserOperationV6. On the Safe Unified Account (SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2, EntryPoint v0.9), it is a UserOperationV9; the signature is always encoded with the multichain scheme (isMultiChainSignature: true), and a multiChainMerkleProof option is rejected. To sign several UserOperations under one signature, use signUserOperationsWithSigners.
Source code
- SafeMultiChainSigAccountV1 / V2: signUserOperationWithSigners
- SafeAccountV0_3_0: signUserOperationWithSigners
- SafeAccountV0_2_0: signUserOperationWithSigners
createAccountCallDataSingleTransaction
Encode calldata for a single MetaTransaction to be executed by Safe account
Usage
In this example, we make a transfer of 1 wei to a random address.
- example.ts
- Param Types
- Return Type
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
const ownerPublicAddress = "0xBdbc5FBC9cA8C3F514D073eC3de840Ac84FC6D31";
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
const callData = SafeAccount.createAccountCallDataSingleTransaction({
to: "0x1a02592A3484c2077d2E5D24482497F85e1980C6",
value: 1n,
data: "0x",
});
console.log("callData: " + callData);
| key | type | description |
|---|---|---|
metaTransaction | object | The MetaTransaction to create calldata for |
metaTransaction.MetaTransaction | object | MetaTransaction is the type of transaction to construct a Safe operation. |
metaTransaction.MetaTransaction.to | string | To address, or the the target contract address for the transaction |
metaTransaction.MetaTransaction.value | bigint | Value transfered if making a native token transfer. (usually 0n for contract interaction with non-native tokens like erc-20 tokens) |
metaTransaction.MetaTransaction.data | string | The call data for the transaction |
metaTransaction.MetaTransaction.operation? | Operation: enum | Default to 0 for a Call. 1 for a Delegate Call. (Optional) |
overrides? | object | Overrides for the default values |
overrides?.safeModuleExecutorFunctionSelector? | object | Safe has two executor functions executeUserOpWithErrorString and executeUserOp. Defaults to executeUserOpWithErrorString |
overrides?.safeModuleExecutorFunctionSelector?.executeUserOpWithErrorString | 0x541d63c8 | Executor that bubbles up the revert reason of the inner call (default) |
overrides?.safeModuleExecutorFunctionSelector?.executeUserOp | 0x7bb37428 | Executor that reverts without returning the inner revert reason |
| key | type | description |
|---|---|---|
callData | string | CallData to be includes in the user operation to send a single transaction |
Example Response
callData: 0x541d63c80000000000000000000000001a02592a3484c2077d2e5d24482497f85e1980c60000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Source code
createAccountCallDataSingleTransaction
createAccountCallDataBatchTransactions
Encode calldata for a list of MetaTransactions to be executed by Safe account
Usage
In this example, we make a transfer to 2 different random addresses, 1 wei each.
- example.ts
- Param Types
- Return Type
import {
SafeMultiChainSigAccountV1 as SafeAccount,
MetaTransaction,
} from "abstractionkit";
const ownerPublicAddress = "0xBdbc5FBC9cA8C3F514D073eC3de840Ac84FC6D31";
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
const tx1: MetaTransaction = {
to: "0x1a02592A3484c2077d2E5D24482497F85e1980C6",
value: 1n,
data: "0x",
};
const tx2: MetaTransaction = {
to: "0x3fe285dcd76bcce4ac92d38a6f2f8e964041e020",
value: 1n,
data: "0x",
};
const callData = SafeAccount.createAccountCallDataBatchTransactions([tx1, tx2]);
console.log("callData: " + callData);
| key | type | description |
|---|---|---|
metaTransactions[] | object | The MetaTransactions to create calldata for |
metaTransactions[].MetaTransaction | object | MetaTransaction is the type of transaction to construct a Safe operation. |
metaTransactions[].MetaTransaction.to | string | To address, or the the target contract address for the transaction |
metaTransactions[].MetaTransaction.value | bigint | Value transfered if making a native token transfer. (usually 0n for contract interaction with non-native tokens like erc-20 tokens) |
metaTransactions[].MetaTransaction.data | string | The call data for the transaction |
metaTransactions[].MetaTransaction.operation? | Operation: enum | Default to 0 for a Call. 1 for a Delegate Call. (Optional) |
overrides? | object | Overrides for the default values |
overrides?.safeModuleExecutorFunctionSelector? | object | Safe has two executor functions executeUserOpWithErrorString and executeUserOp. Defaults to executeUserOpWithErrorString |
overrides?.safeModuleExecutorFunctionSelector?.executeUserOpWithErrorString | 0x541d63c8 | Executor that bubbles up the revert reason of the inner call (default) |
overrides?.safeModuleExecutorFunctionSelector?.executeUserOp | 0x7bb37428 | Executor that reverts without returning the inner revert reason |
overrides?.multisendContractAddress? | string | Address of the Safe MultiSend contract. Default is "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526". |
| key | type | description |
|---|---|---|
callData | string | CallData to be includes in the user operation to send a single transaction |
Example Response
callData: 0x541d63c800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001048d80ff0a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000aa001a02592a3484c2077d2e5d24482497f85e1980c600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000003fe285dcd76bcce4ac92d38a6f2f8e964041e020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Source code
createAccountCallDataBatchTransactions
getUserOperationEip712Hash
Create a userOperation eip712 hash
Usage
- example
- Param Types
- Return Types
import {
SafeMultiChainSigAccountV1 as SafeAccount,
UserOperationV9
} from "abstractionkit";
const userOperation: UserOperationV9 = await smartAccount.createUserOperation(..)
const safeUserOpHash = SafeAccount.getUserOperationEip712Hash(userOperation, chainId);
console.log(safeUserOpHash);
| key | type | description |
|---|---|---|
userOperation | object | UserOperation to hash |
userOperation.sender | string | The account making the operation |
userOperation.nonce | bigint | Anti-replay parameter (see “Semi-abstracted Nonce Support” ) |
userOperation.factory | string | null | account factory, only for new accounts (null if the account already exists) |
userOperation.factoryData | string | null | data for account factory (null if the account already exists) |
userOperation.callData | string | The data to pass to the sender during the main execution call |
userOperation.callGasLimit | bigint | The amount of gas to allocate the main execution call |
userOperation.verificationGasLimit | bigint | The amount of gas to allocate for the verification step |
userOperation.preVerificationGas | bigint | Extra gas to pay the bundler |
userOperation.maxFeePerGas | bigint | Maximum fee per gas (similar to EIP-1559 max_fee_per_gas) |
userOperation.maxPriorityFeePerGas | bigint | Maximum priority fee per gas (similar to EIP-1559 max_priority_fee_per_gas) |
userOperation.paymaster | string | null | Address of paymaster contract (null if account pays for itself) |
userOperation.paymasterVerificationGasLimit | bigint | null | The amount of gas to allocate for the paymaster verification step |
userOperation.paymasterPostOpGasLimit | bigint | null | The amount of gas to allocate for the paymaster post-operation code |
userOperation.paymasterData | string | null | Data for paymaster (null if no paymaster) |
userOperation.signature | string | Data passed into the account to verify authorization |
chainId | bigint | target chain id |
overrides? | object | Overrides for the default values |
overrides?.validAfter? | bigint | Timestamp the signature will be valid after |
overrides?.validUntil? | bigint | Timestamp the signature will be valid until |
overrides?.entrypointAddress? | string | Target entrypoint. Defaults to EP v0.7 |
overrides?.safe4337ModuleAddress? | string | Defaults to official 4337 safe module address |
| key | type | description |
|---|---|---|
userOperation | string | userOperation hash |
Example Response
0xec030c825b12b398c10f1b552004e43ec753fdf001e1c1daa1ceffe4f7ff5056
On SafeAccountV0_2_0 (EntryPoint v0.6), userOperation is a UserOperationV6 and entrypointAddress defaults to EntryPoint v0.6. On the Safe Unified Account (SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2, EntryPoint v0.9), it is a UserOperationV9 and entrypointAddress defaults to EntryPoint v0.9. Each class defaults safe4337ModuleAddress to its own Safe 4337 module.
Source code
- SafeMultiChainSigAccountV1 / V2: getUserOperationEip712Hash
- SafeAccountV0_3_0: getUserOperationEip712Hash
- SafeAccountV0_2_0: getUserOperationEip712Hash
getUserOperationEip712Data
A static method that returns the EIP-712 domain data for a userOp
- Param Types
- Return Types
| key | type | description |
|---|---|---|
userOperation | object | UserOp to hash |
userOperation.sender | string | The account making the operation |
userOperation.nonce | bigint | Anti-replay parameter (see “Semi-abstracted Nonce Support” ) |
userOperation.factory | string | null | account factory, only for new accounts (null if the account already exists) |
userOperation.factoryData | string | null | data for account factory (null if the account already exists) |
userOperation.callData | string | The data to pass to the sender during the main execution call |
userOperation.callGasLimit | bigint | The amount of gas to allocate the main execution call |
userOperation.verificationGasLimit | bigint | The amount of gas to allocate for the verification step |
userOperation.preVerificationGas | bigint | Extra gas to pay the bundler |
userOperation.maxFeePerGas | bigint | Maximum fee per gas (similar to EIP-1559 max_fee_per_gas) |
userOperation.maxPriorityFeePerGas | bigint | Maximum priority fee per gas (similar to EIP-1559 max_priority_fee_per_gas) |
userOperation.paymaster | string | null | Address of paymaster contract (null if account pays for itself) |
userOperation.paymasterVerificationGasLimit | bigint | null | The amount of gas to allocate for the paymaster verification step |
userOperation.paymasterPostOpGasLimit | bigint | null | The amount of gas to allocate for the paymaster post-operation code |
userOperation.paymasterData | string | null | Data for paymaster (null if no paymaster) |
userOperation.signature | string | Data passed into the account to verify authorization |
chainId | bigint | target chain id |
overrides? | object | optional overrides |
overrides?.validAfter? | bigint | Timestamp the signature will be valid after |
overrides?.validUntil? | bigint | Timestamp the signature will be valid until |
overrides?.entrypointAddress? | string | Address of the entrypoint contract |
overrides?.safe4337ModuleAddress? | string | Address of the Safe 4337 module. |
| key | type | description |
|---|---|---|
domain | object | Safe userOperation typed data domain |
domain.chainId | number | target chain id |
domain.verifyingContract | string | safe 4337 module contract on traget entrypoint |
types | Record<string, {name: string;type: string;}[]> | The Safe Typed structured data to be signed |
messageValue | object | Safe userOperation typed message value |
messageValue.safe | string | the userop sender address of the safe account |
messageValue.nonce | bigint | Anti-replay parameter (see “Semi-abstracted Nonce Support” ) |
messageValue.initCode | string | The initCode of the account (needed if and only if the account is not yet on-chain and needs to be created) |
messageValue.callData | string | The data to pass to the sender during the main execution call |
messageValue.callGasLimit | bigint | The amount of gas to allocate the main execution call |
messageValue.verificationGasLimit | bigint | The amount of gas to allocate for the verification step |
messageValue.preVerificationGas | bigint | The amount of gas to pay for to compensate the bundler for pre-verification execution and calldata |
messageValue.maxFeePerGas | bigint | Maximum fee per gas (similar to EIP-1559 max_fee_per_gas) |
messageValue.maxPriorityFeePerGas | bigint | Maximum priority fee per gas (similar to EIP-1559 max_priority_fee_per_gas) |
messageValue.paymasterAndData | string | Address of paymaster sponsoring the transaction, followed by extra data to send to the paymaster (empty for self-sponsored transaction). Revolves to '0x' if not using a paymaster, and a paymasterDummyData when estimating gas |
messageValue.validAfter | bigint | Timestamp the signature will be valid after |
messageValue.validUntil | bigint | Timestamp the signature will be valid until |
messageValue.entryPoint | string | EntryPoint contract address |
On SafeAccountV0_2_0 (EntryPoint v0.6), userOperation is a UserOperationV6. On the Safe Unified Account (SafeMultiChainSigAccountV1 and SafeMultiChainSigAccountV2, EntryPoint v0.9), it is a UserOperationV9. Each class defaults entrypointAddress and safe4337ModuleAddress to its own EntryPoint and Safe 4337 module.
Source code
- SafeMultiChainSigAccountV1 / V2: getUserOperationEip712Data
- SafeAccountV0_3_0: getUserOperationEip712Data
- SafeAccountV0_2_0: getUserOperationEip712Data
formatEip712SignaturesToUseroperationSignature
A static method to format a list of eip712 signatures to a userOperation signature.
Usage
- ethers example
- viem example
- Param Types
- Response Type
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
import { Wallet } from "ethers";
const ownerPrivateKey = process.env.PRIVATE_KEY as string;
const signer = new Wallet(ownerPrivateKey);
const ownerPublicAddress = signer.address;
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
let userOperation = ... // smartAccount.createUserOperation(..)
const safeUserOpHash = SafeAccount.getUserOperationEip712Hash(userOperation, chainId);
const signature = signer.signingKey.sign(safeUserOpHash).serialized;
const formatedSig = SafeAccount.formatEip712SignaturesToUseroperationSignature(
[ownerPublicAddress],
[signature],
{ isMultiChainSignature: true }, // required for SafeMultiChainSigAccountV1 and V2; omit for SafeAccountV0_3_0 and V0_2_0
);
userOperation.signature = formatedSig;
import { SafeMultiChainSigAccountV1 as SafeAccount } from "abstractionkit";
import { privateKeyToAccount } from "viem/accounts";
const ownerPrivateKey = process.env.PRIVATE_KEY as string;
const signer = privateKeyToAccount(process.env.PRIVATE_KEY1 as `0x${string}`);
const ownerPublicAddress = signer.address;
const smartAccount = SafeAccount.initializeNewAccount([ownerPublicAddress]);
let userOperation = ... // smartAccount.createUserOperation(..)
const chainId = BigInt(process.env.CHAIN_ID as string);
const safeUserOpHash = SafeAccount.getUserOperationEip712Hash(
userOperation,
chainId
) as `0x${string}`;
const signature = await signer.sign({ hash: safeUserOpHash });
const formatedSig = SafeAccount.formatEip712SignaturesToUseroperationSignature(
[ownerPublicAddress],
[signature],
{ isMultiChainSignature: true }, // required for SafeMultiChainSigAccountV1 and V2; omit for SafeAccountV0_3_0 and V0_2_0
);
userOperation.signature = formatedSig;
| key | type | description |
|---|---|---|
signersAddresses | string[] | Public addresses of the signers, in the same order as signatures |
signatures | string[] | EIP-712 signatures, one per signer address |
overrides? | object | overrides for the default values |
overrides?.validAfter? | bigint | Timestamp the signature will be valid after |
overrides?.validUntil? | bigint | Timestamp the signature will be valid until |
overrides?.isMultiChainSignature? | boolean | Whether this is a multi-chain signature using Merkle proofs |
overrides?.merkleProof? | string | Merkle proof for multi-chain signature verification |
| key | type | description |
|---|---|---|
signature | string | The EIP-712 Signature |
Example Response
0x0000000000000000000000006da39f6f7b0d2c0035084d3c313350697b3167ff591a84bf0b4bb4741224b5d226682ec306544c091e2b6535042c900b459282edfe98e393d552963ca8db11731c
On the Safe Unified Account, signatures always use the multichain encoding: pass { isMultiChainSignature: true } as overrides. See Manual EIP-712 signing for a single UserOperation.