A set of utilities for ERC-4337 Account Abstraction to help you with your development.
UserOperation utils
createUserOperationHash
Computes the hash of a UserOperation, which is used as the unique identifier for the operation on-chain.
- example.ts
- Param Types
- Return Type
example.ts
import { createUserOperationHash } from "abstractionkit";
const userOpHash = createUserOperationHash(
userOperation,
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
11155111n
);
| key | type | description |
|---|
useroperation | UserOperationV6 | UserOperationV7 | UserOperationV8 | UserOperationV9 | The UserOperation to hash |
entrypointAddress | string | The address of the EntryPoint contract |
chainId | bigint | The chain ID of the target network |
| key | type | description |
|---|
userOperationHash | string | The keccak256 hash of the packed UserOperation |
Source code
createUserOperationHash
createPackedUserOperationV6
Encodes a UserOperationV6 into its packed ABI representation, suitable for hashing or on-chain verification.
- example.ts
- Param Types
- Return Type
example.ts
import { createPackedUserOperationV6 } from "abstractionkit";
const packed = createPackedUserOperationV6(userOperationV6);
| key | type | description |
|---|
useroperation | UserOperationV6 | A UserOperation following the EntryPoint v0.6 format |
| key | type | description |
|---|
packedUserOperation | string | ABI-encoded packed representation of the UserOperation |
Source code
createPackedUserOperationV6
createPackedUserOperationV7
Encodes a UserOperationV7 into its packed ABI representation, suitable for hashing or on-chain verification.
- example.ts
- Param Types
- Return Type
example.ts
import { createPackedUserOperationV7 } from "abstractionkit";
const packed = createPackedUserOperationV7(userOperationV7);
| key | type | description |
|---|
useroperation | UserOperationV7 | A UserOperation following the EntryPoint v0.7 format |
| key | type | description |
|---|
packedUserOperation | string | ABI-encoded packed representation of the UserOperation |
Source code
createPackedUserOperationV7
fetchAccountNonce
Fetches the current nonce for a smart account from the EntryPoint. Accepts an optional key parameter (default 0) that enables parallel nonce channels, allowing multiple independent UserOperations to be submitted concurrently.
- example.ts
- Param Types
- Return Type
example.ts
import { fetchAccountNonce } from "abstractionkit";
const nonce = await fetchAccountNonce(
"https://ethereum-sepolia-rpc.publicnode.com",
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
"0xYourSmartAccountAddress"
);
| key | type | description |
|---|
rpcUrl | string | The JSON-RPC URL of an Ethereum node |
entryPoint | string | The address of the EntryPoint contract |
account | string | The smart account address to query the nonce for |
key | number | Nonce key for parallel nonce channels (default: 0). Using different keys allows multiple independent UserOperations to be submitted concurrently. |
| key | type | description |
|---|
nonce | Promise<bigint> | The current nonce of the account in the EntryPoint |
Source code
fetchAccountNonce
calculateUserOperationMaxGasCost
Calculates the maximum possible gas cost (in wei) for a UserOperation based on its gas limits and fee parameters.
- example.ts
- Param Types
- Return Type
example.ts
import { calculateUserOperationMaxGasCost } from "abstractionkit";
const maxCost = calculateUserOperationMaxGasCost(userOperation);
| key | type | description |
|---|
useroperation | UserOperationV6 | UserOperationV7 | The UserOperation to calculate the maximum gas cost for |
| key | type | description |
|---|
maxGasCost | bigint | The maximum gas cost in wei that the UserOperation could consume |
Source code
calculateUserOperationMaxGasCost
getBalanceOf
Returns the balance of an account deposited in the EntryPoint contract.
- example.ts
- Param Types
- Return Type
example.ts
import { getBalanceOf } from "abstractionkit";
const balance = await getBalanceOf(
"https://ethereum-sepolia-rpc.publicnode.com",
"0xYourAccountAddress",
"0x0000000071727De22E5E9d8BAf0edAc6f37da032"
);
| key | type | description |
|---|
nodeRpcUrl | string | The JSON-RPC URL of an Ethereum node |
address | string | The account address to query the balance for |
entrypointAddress | string | The address of the EntryPoint contract |
| key | type | description |
|---|
balance | Promise<bigint> | The account's deposited balance in the EntryPoint (in wei) |
Source code
getBalanceOf
getDepositInfo
Returns the full deposit information of an account in the EntryPoint contract, including deposit balance, stake status, and unstake delay.
- example.ts
- Param Types
- Return Type
example.ts
import { getDepositInfo } from "abstractionkit";
const info = await getDepositInfo(
"https://ethereum-sepolia-rpc.publicnode.com",
"0xYourAccountAddress",
"0x0000000071727De22E5E9d8BAf0edAc6f37da032"
);
| key | type | description |
|---|
nodeRpcUrl | string | The JSON-RPC URL of an Ethereum node |
address | string | The account address to query deposit information for |
entrypointAddress | string | The address of the EntryPoint contract |
| key | type | description |
|---|
depositInfo | | key | type | description |
|---|
deposit | bigint | The deposited balance in the EntryPoint (in wei) | staked | boolean | Whether the account has an active stake | stake | bigint | The staked amount (in wei) | unstakeDelaySec | bigint | The delay in seconds before unstaked funds can be withdrawn | withdrawTime | bigint | The earliest time at which a withdrawal can complete |
| The full deposit information from the EntryPoint |
DepositInfo
| key | type | description |
|---|
deposit | bigint | The deposited balance in the EntryPoint (in wei) |
staked | boolean | Whether the account has an active stake |
stake | bigint | The staked amount (in wei) |
unstakeDelaySec | bigint | The delay in seconds before unstaked funds can be withdrawn |
withdrawTime | bigint | The earliest time at which a withdrawal can complete |
Source code
getDepositInfo
Simulation utils
simulateUserOperationWithTenderlyAndCreateShareLink
Simulates a UserOperation via the EntryPoint's handleOps on Tenderly and returns a shareable dashboard link.
- example.ts
- Param Types
- Return Type
example.ts
import { simulateUserOperationWithTenderlyAndCreateShareLink } from "abstractionkit";
const { simulation, simulationShareLink } =
await simulateUserOperationWithTenderlyAndCreateShareLink(
"my-account",
"my-project",
"my-access-key",
11155111n,
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
userOperation
);
| key | type | description |
|---|
tenderlyAccountSlug | string | Your Tenderly account slug |
tenderlyProjectSlug | string | Your Tenderly project slug |
tenderlyAccessKey | string | Your Tenderly API access key |
chainId | bigint | The chain ID of the target network |
entrypointAddress | string | The address of the EntryPoint contract |
userOperation | UserOperationV6 | UserOperationV7 | UserOperationV8 | UserOperationV9 | The UserOperation to simulate |
blockNumber | number | null | Block number to simulate against (default: null for latest) |
stateOverrides? | OverrideType | null | Optional state overrides applied during simulation |
| key | type | description |
|---|
simulation | SingleTransactionTenderlySimulationResult | The simulation result from Tenderly |
simulationShareLink | string | A shareable Tenderly dashboard link for the simulation |
Source code
simulateUserOperationWithTenderlyAndCreateShareLink
simulateUserOperationCallDataWithTenderlyAndCreateShareLink
Simulates UserOperation callData with Tenderly and returns shareable links. Unlike simulateUserOperationWithTenderlyAndCreateShareLink, this simulates the inner call data rather than the full EntryPoint handleOps flow.
- example.ts
- Param Types
- Return Type
example.ts
import { simulateUserOperationCallDataWithTenderlyAndCreateShareLink } from "abstractionkit";
const { simulation, callDataSimulationShareLink } =
await simulateUserOperationCallDataWithTenderlyAndCreateShareLink(
"my-account",
"my-project",
"my-access-key",
11155111n,
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
userOperation
);
| key | type | description |
|---|
tenderlyAccountSlug | string | Your Tenderly account slug |
tenderlyProjectSlug | string | Your Tenderly project slug |
tenderlyAccessKey | string | Your Tenderly API access key |
chainId | bigint | The chain ID of the target network |
entrypointAddress | string | The address of the EntryPoint contract |
userOperation | UserOperationV6ToSimulate | UserOperationV7ToSimulate | UserOperationV8ToSimulate | UserOperationV9ToSimulate | A partial UserOperation with at least sender, nonce, and callData populated |
blockNumber | number | null | Block number to simulate against (default: null for latest) |
stateOverrides? | OverrideType | null | Optional state overrides applied during simulation |
| key | type | description |
|---|
simulation | TenderlySimulationResult | The simulation result from Tenderly |
callDataSimulationShareLink | string | A shareable Tenderly dashboard link for the callData simulation |
accountDeploymentSimulationShareLink? | string | A shareable link for the account deployment simulation, if a factory was provided |
Source code
simulateUserOperationCallDataWithTenderlyAndCreateShareLink
simulateSenderCallDataWithTenderlyAndCreateShareLink
Simulates sender callData directly with Tenderly and returns shareable links. Useful for simulating the execution of callData from a specific sender address without wrapping it in a full UserOperation.
- example.ts
- Param Types
- Return Type
example.ts
import { simulateSenderCallDataWithTenderlyAndCreateShareLink } from "abstractionkit";
const { simulation, callDataSimulationShareLink } =
await simulateSenderCallDataWithTenderlyAndCreateShareLink(
"my-account",
"my-project",
"my-access-key",
11155111n,
"0x0000000071727De22E5E9d8BAf0edAc6f37da032",
"0xSenderAddress",
"0xCallData"
);
| key | type | description |
|---|
tenderlyAccountSlug | string | Your Tenderly account slug |
tenderlyProjectSlug | string | Your Tenderly project slug |
tenderlyAccessKey | string | Your Tenderly API access key |
chainId | bigint | The chain ID of the target network |
entrypointAddress | string | The address of the EntryPoint contract |
sender | string | The sender address to simulate the call from |
callData | string | The call data to simulate |
factory | string | null | Factory address if the account needs deployment (default: null) |
factoryData | string | null | Factory init data for account deployment (default: null) |
blockNumber | number | null | Block number to simulate against (default: null for latest) |
stateOverrides? | OverrideType | null | Optional state overrides applied during simulation |
| key | type | description |
|---|
simulation | TenderlySimulationResult | The simulation result from Tenderly |
callDataSimulationShareLink | string | A shareable Tenderly dashboard link for the callData simulation |
accountDeploymentSimulationShareLink? | string | A shareable link for the account deployment simulation, if a factory was provided |
Source code
simulateSenderCallDataWithTenderlyAndCreateShareLink
Multicall utils
encodeMultiSendCallData
Encodes an array of MetaTransactions into a single callData payload for the MultiSend contract.
- example.ts
- Param Types
- Return Type
example.ts
import { encodeMultiSendCallData } from "abstractionkit";
const callData = encodeMultiSendCallData([
{
to: "0xTokenAddress",
value: 0n,
data: "0xTransferCallData",
operation: 0,
},
{
to: "0xAnotherContract",
value: 0n,
data: "0xAnotherCallData",
operation: 0,
},
]);
| key | type | description |
|---|
metaTransactions | MetaTransaction[] | Array of MetaTransactions to encode into a single MultiSend call |
MetaTransaction
| key | type | description |
|---|
to | string | Target contract address |
value | bigint | Value to send with the transaction (in wei) |
data | string | Call data for the transaction |
operation | Operation | Operation type: 0 for Call, 1 for DelegateCall |
| key | type | description |
|---|
callData | string | ABI-encoded callData for the MultiSend contract |
Source code
encodeMultiSendCallData
decodeMultiSendCallData
Decodes encoded MultiSend callData back into a readable representation.
- example.ts
- Param Types
- Return Type
example.ts
import { decodeMultiSendCallData } from "abstractionkit";
const decoded = decodeMultiSendCallData(encodedCallData);
| key | type | description |
|---|
callData | string | The encoded MultiSend callData to decode |
| key | type | description |
|---|
decoded | string | Decoded representation of the MultiSend transactions |
Source code
decodeMultiSendCallData
Generic Ethereum utils
fetchGasPrice
Fetches the current gas price from an Ethereum node, returning maxFeePerGas and maxPriorityFeePerGas for a given gas level.
- example.ts
- Param Types
- Return Type
example.ts
import { fetchGasPrice, GasOption } from "abstractionkit";
const [maxFeePerGas, maxPriorityFeePerGas] = await fetchGasPrice(
"https://ethereum-sepolia-rpc.publicnode.com",
GasOption.Medium
);
| key | type | description |
|---|
providerRpc | string | The JSON-RPC URL of an Ethereum node |
gasLevel | GasOption | Gas price tier: GasOption.Slow, GasOption.Medium (default), or GasOption.Fast |
| key | type | description |
|---|
gasPrices | [bigint, bigint] | A tuple of [maxFeePerGas, maxPriorityFeePerGas] |
Source code
fetchGasPrice
createCallData
Encodes a function call into ABI-encoded call data by combining a function selector with its encoded parameters.
- example.ts
- Param Types
- Return Type
example.ts
import { createCallData } from "abstractionkit";
const callData = createCallData(
"0xa9059cbb",
["address", "uint256"],
["0xRecipientAddress", 1000000n]
);
| key | type | description |
|---|
functionSelector | string | The 4-byte function selector (e.g. from getFunctionSelector) |
functionInputAbi | string[] | Array of ABI type strings for the function parameters (e.g. ["address", "uint256"]) |
functionInputParameters | AbiInputValue[] | Array of values matching the ABI types |
| key | type | description |
|---|
callData | string | The ABI-encoded call data combining the selector and encoded parameters |
Source code
createCallData
getFunctionSelector
Computes the 4-byte function selector from a Solidity function signature string.
- example.ts
- Param Types
- Return Type
example.ts
import { getFunctionSelector } from "abstractionkit";
const selector = getFunctionSelector("transfer(address,uint256)");
| key | type | description |
|---|
functionSignature | string | The function signature string (e.g. "transfer(address,uint256)") |
| key | type | description |
|---|
selector | string | The first 4 bytes (8 hex characters) of the keccak256 hash of the function signature |
Source code
getFunctionSelector
sendJsonRpcRequest
Sends a JSON-RPC request to the given URL. Accepts optional headers (defaults to {"Content-Type": "application/json"}) and an optional paramsKeyName for non-standard JSON-RPC endpoints.
- example.ts
- Param Types
- Return Type
example.ts
import { sendJsonRpcRequest } from "abstractionkit";
const result = await sendJsonRpcRequest(
"https://ethereum-sepolia-rpc.publicnode.com",
"eth_blockNumber",
[]
);
| key | type | description |
|---|
rpcUrl | string | The JSON-RPC endpoint URL |
method | string | The JSON-RPC method name |
params | JsonRpcParam | The parameters to pass to the JSON-RPC method |
headers | Record<string, string> | HTTP headers for the request (default: {"Content-Type": "application/json"}) |
paramsKeyName | string | Key name for the params field in the JSON-RPC body (default: "params"). Useful for non-standard JSON-RPC endpoints. |
| key | type | description |
|---|
result | Promise<JsonRpcResult> | The JSON-RPC result, or an error if the request failed |
Source code
sendJsonRpcRequest
sendEthCallRequest
Executes an eth_call against an Ethereum node and returns the result. Useful for reading contract state without submitting a transaction.
- example.ts
- Param Types
- Return Type
example.ts
import { sendEthCallRequest } from "abstractionkit";
const result = await sendEthCallRequest(
"https://ethereum-sepolia-rpc.publicnode.com",
{
to: "0xContractAddress",
data: "0xCallData",
},
"latest"
);
| key | type | description |
|---|
nodeRpcUrl | string | The JSON-RPC URL of an Ethereum node |
ethCallTransaction | EthCallTransaction | The transaction object for eth_call (to, data, and optionally from/value) |
blockNumber | string | bigint | Block number to execute the call against, or "latest" |
stateOverrides? | object | Optional state overrides to apply during the call |
| key | type | description |
|---|
result | Promise<string> | The hex-encoded return data from the contract call |
Source code
sendEthCallRequest
sendEthGetCodeRequest
Retrieves the bytecode deployed at a given contract address using eth_getCode.
- example.ts
- Param Types
- Return Type
example.ts
import { sendEthGetCodeRequest } from "abstractionkit";
const code = await sendEthGetCodeRequest(
"https://ethereum-sepolia-rpc.publicnode.com",
"0xContractAddress",
"latest"
);
| key | type | description |
|---|
nodeRpcUrl | string | The JSON-RPC URL of an Ethereum node |
contractAddress | string | The address to retrieve the deployed bytecode for |
blockNumber | string | bigint | Block number to query, or "latest" |
| key | type | description |
|---|
code | Promise<string> | The hex-encoded bytecode deployed at the address, or "0x" if no code exists |
Source code
sendEthGetCodeRequest
getDelegatedAddress
Checks whether an EOA has an active EIP-7702 delegation and returns the delegated address, or null if the account is not delegated.
- example.ts
- Param Types
- Return Type
example.ts
import { getDelegatedAddress } from "abstractionkit";
const delegatee = await getDelegatedAddress(
"0xYourEOAAddress",
"https://ethereum-sepolia-rpc.publicnode.com"
);
if (delegatee) {
console.log("Delegated to:", delegatee);
} else {
console.log("Not delegated");
}
| key | type | description |
|---|
accountAddress | string | The EOA address to check for EIP-7702 delegation |
providerRpc | string | The JSON-RPC URL of an Ethereum node |
| key | type | description |
|---|
delegatedAddress | Promise<string | null> | The address the EOA is delegated to, or null if not delegated |
Source code
getDelegatedAddress
EIP-7702 Utilities
createAndSignEip7702DelegationAuthorization
Creates and signs an EIP-7702 delegation authorization, allowing an EOA to delegate its code to a specified contract address. Accepts either a hex-encoded private key string for synchronous signing, or an async signer callback (hash: string) => Promise<string> for use with viem, ethers Signers, hardware wallets, or MPC signers.
- example.ts
- Param Types
- Return Type
example.ts
import { createAndSignEip7702DelegationAuthorization } from "abstractionkit";
const authorization = createAndSignEip7702DelegationAuthorization(
11155111n,
"0xDelegateeContractAddress",
0n,
"0xYourPrivateKey"
);
const authorization = await createAndSignEip7702DelegationAuthorization(
11155111n,
"0xDelegateeContractAddress",
0n,
async (hash) => {
return await wallet.signMessage(hash);
}
);
| key | type | description |
|---|
chainId | bigint | The chain ID for the delegation authorization |
address | string | The contract address to delegate to |
nonce | bigint | The authorization nonce of the EOA |
signer | string | ((hash: string) => Promise<string>) | Either a hex-encoded private key for synchronous signing, or an async callback that receives the authorization hash and returns a signature. The callback form supports viem wallets, ethers Signers, hardware wallets, and MPC signers. |
| key | type | description |
|---|
authorization | Authorization7702Hex | The signed EIP-7702 delegation authorization |
Authorization7702Hex
| key | type | description |
|---|
chainId | string | Hex-encoded chain ID |
address | string | The delegatee contract address |
nonce | string | Hex-encoded authorization nonce |
yParity | string | Hex-encoded y-parity of the signature |
r | string | Hex-encoded r component of the signature |
s | string | Hex-encoded s component of the signature |
Source code
createAndSignEip7702DelegationAuthorization
createRevokeDelegationAuthorization
Creates a signed authorization that revokes an existing EIP-7702 delegation by setting the delegatee address to the zero address, restoring the EOA to a normal account.
- example.ts
- Param Types
- Return Type
example.ts
import { createRevokeDelegationAuthorization } from "abstractionkit";
const revokeAuth = createRevokeDelegationAuthorization(
11155111n,
0n,
"0xYourPrivateKey"
);
| key | type | description |
|---|
chainId | bigint | The chain ID for the revocation authorization |
nonce | bigint | The authorization nonce of the EOA |
eoaPrivateKey | string | The hex-encoded private key of the EOA |
| key | type | description |
|---|
authorization | Authorization7702Hex | A signed authorization that delegates to address(0), revoking the existing delegation |
Authorization7702Hex
| key | type | description |
|---|
chainId | string | Hex-encoded chain ID |
address | string | The delegatee contract address |
nonce | string | Hex-encoded authorization nonce |
yParity | string | Hex-encoded y-parity of the signature |
r | string | Hex-encoded r component of the signature |
s | string | Hex-encoded s component of the signature |
Source code
createRevokeDelegationAuthorization
createEip7702DelegationAuthorizationHash
Computes the keccak256 hash of an EIP-7702 delegation authorization using the MAGIC prefix (0x05) as defined in the EIP-7702 spec. Useful when signing the authorization externally.
- example.ts
- Param Types
- Return Type
example.ts
import { createEip7702DelegationAuthorizationHash } from "abstractionkit";
const hash = createEip7702DelegationAuthorizationHash(
11155111n,
"0xDelegateeContractAddress",
0n
);
| key | type | description |
|---|
chainId | bigint | The chain ID for the authorization |
address | string | The delegatee contract address |
nonce | bigint | The authorization nonce |
| key | type | description |
|---|
hash | string | The keccak256 hash of the RLP-encoded authorization with the MAGIC prefix (0x05), as specified by EIP-7702 |
Source code
createEip7702DelegationAuthorizationHash
createAndSignEip7702RawTransaction
Creates and signs a raw EIP-7702 (set-code, type 0x04) transaction with an authorization list. The transaction is RLP-encoded and includes the type prefix, ready for eth_sendRawTransaction.
- example.ts
- Param Types
- Return Type
example.ts
import { createAndSignEip7702RawTransaction } from "abstractionkit";
const rawTx = createAndSignEip7702RawTransaction(
11155111n,
0n,
2000000000n,
20000000000n,
21000n,
"0xDestination",
0n,
"0x",
[],
[authorization],
"0xYourPrivateKey"
);
| key | type | description |
|---|
chainId | bigint | The chain ID for the transaction |
nonce | bigint | The transaction nonce |
max_priority_fee_per_gas | bigint | Maximum priority fee per gas (EIP-1559) |
max_fee_per_gas | bigint | Maximum fee per gas (EIP-1559) |
gas_limit | bigint | Gas limit for the transaction |
destination | string | The target address for the transaction |
value | bigint | Value to send in wei |
data | string | The call data for the transaction |
access_list | [string, string[]][] | EIP-2930 access list: array of [address, storageKeys] tuples |
authorization_list | Authorization7702[] | Array of EIP-7702 authorizations to include in the transaction |
eoaPrivateKey | string | The hex-encoded private key to sign the transaction with |
| key | type | description |
|---|
rawTransaction | string | The signed, RLP-encoded EIP-7702 transaction with the 0x04 type prefix, ready for eth_sendRawTransaction |
Source code
createAndSignEip7702RawTransaction
createEip7702TransactionHash
Computes the keccak256 hash of an EIP-7702 transaction for signing purposes, using the type 0x04 prefix and RLP encoding.
- example.ts
- Param Types
- Return Type
example.ts
import { createEip7702TransactionHash } from "abstractionkit";
const txHash = createEip7702TransactionHash(
11155111n,
0n,
2000000000n,
20000000000n,
21000n,
"0xDestination",
0n,
"0x",
[],
[authorization]
);
| key | type | description |
|---|
chainId | bigint | The chain ID for the transaction |
nonce | bigint | The transaction nonce |
max_priority_fee_per_gas | bigint | Maximum priority fee per gas (EIP-1559) |
max_fee_per_gas | bigint | Maximum fee per gas (EIP-1559) |
gas_limit | bigint | Gas limit for the transaction |
destination | string | The target address for the transaction |
value | bigint | Value to send in wei |
data | string | The call data for the transaction |
access_list | [string, string[]][] | EIP-2930 access list: array of [address, storageKeys] tuples |
authorization_list | Authorization7702[] | Array of EIP-7702 authorizations to include in the transaction |
| key | type | description |
|---|
hash | string | The keccak256 hash of the RLP-encoded EIP-7702 transaction with the 0x04 type prefix, used for signing |
Source code
createEip7702TransactionHash