# Utilities

A set of utilities for ERC-4337 Account Abstraction to help you with your development.

## UserOperation utils[​](#useroperation-utils "Direct link to UserOperation utils")

### createUserOperationHash[​](#createuseroperationhash "Direct link to 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[​](#source-code "Direct link to Source code")

[createUserOperationHash](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L50)

### createPackedUserOperationV6[​](#createpackeduseroperationv6 "Direct link to 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[​](#source-code-1 "Direct link to Source code")

[createPackedUserOperationV6](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L313)

### createPackedUserOperationV7[​](#createpackeduseroperationv7 "Direct link to 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[​](#source-code-2 "Direct link to Source code")

[createPackedUserOperationV7](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L353)

### fetchAccountNonce[​](#fetchaccountnonce "Direct link to 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[​](#source-code-3 "Direct link to Source code")

[fetchAccountNonce](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L586)

### calculateUserOperationMaxGasCost[​](#calculateuseroperationmaxgascost "Direct link to 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[​](#source-code-4 "Direct link to Source code")

[calculateUserOperationMaxGasCost](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L645)

### JsonRpcNode[​](#jsonrpcnode "Direct link to JsonRpcNode")

`JsonRpcNode` wraps common Ethereum node calls behind the same `Transport` abstraction used by Bundler and Paymaster services. Use it for node reads instead of the removed top-level URL helpers `fetchGasPrice`, `getBalanceOf`, `getDepositInfo`, and `getDelegatedAddress`.

* example.ts
* Transport

example.ts

```
import { GasOption, JsonRpcNode } from "abstractionkit";



const node = new JsonRpcNode("https://ethereum-sepolia-rpc.publicnode.com");



const [maxFeePerGas, maxPriorityFeePerGas] = await node.getFeeData(GasOption.Medium);

const deposit = await node.getEntryPointDeposit(

  "0xYourAccountAddress",

  "0x0000000071727De22E5E9d8BAf0edAc6f37da032",

);

const depositInfo = await node.getEntryPointDepositInfo(

  "0xYourAccountAddress",

  "0x0000000071727De22E5E9d8BAf0edAc6f37da032",

);

const delegatee = await node.getDelegatedAddress("0xYourEOAAddress");
```

transport.ts

```
import { JsonRpcNode, type Transport } from "abstractionkit";



const transport: Transport = {

  request: async ({ method, params }, options) => {

    return myRpcClient.request({ method, params }, { signal: options?.signal });

  },

};



const node = new JsonRpcNode(transport);

const code = await node.getCode("0xYourAccountAddress");
```

#### Methods[​](#methods "Direct link to Methods")

* `chainId()`
* `blockNumber()`
* `getCode(address)`
* `call(transaction)`
* `getTransactionCount(address)`
* `getFeeData(gasOption?)`
* `getDelegatedAddress(eoaAddress)`
* `getEntryPointNonce(entryPoint, account, key?)`
* `getEntryPointDeposit(address, entryPoint)`
* `getEntryPointDepositInfo(address, entryPoint)`
* `request(args, options?)`

#### Source code[​](#source-code-5 "Direct link to Source code")

[JsonRpcNode](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/transport/JsonRpcNode.ts#L50)

### getBalanceOf[​](#getbalanceof "Direct link to getBalanceOf")

Deprecated in `v0.3.8`. Use `JsonRpcNode#getEntryPointDeposit` instead.

migration.ts

```
import { JsonRpcNode } from "abstractionkit";



const node = new JsonRpcNode("https://ethereum-sepolia-rpc.publicnode.com");

const balance = await node.getEntryPointDeposit(

  "0xYourAccountAddress",

  "0x0000000071727De22E5E9d8BAf0edAc6f37da032",

);
```

### getDepositInfo[​](#getdepositinfo "Direct link to getDepositInfo")

Deprecated in `v0.3.8`. Use `JsonRpcNode#getEntryPointDepositInfo` instead.

migration.ts

```
import { JsonRpcNode } from "abstractionkit";



const node = new JsonRpcNode("https://ethereum-sepolia-rpc.publicnode.com");

const info = await node.getEntryPointDepositInfo(

  "0xYourAccountAddress",

  "0x0000000071727De22E5E9d8BAf0edAc6f37da032",

);
```

## Simulation utils[​](#simulation-utils "Direct link to Simulation utils")

### simulateUserOperationWithTenderlyAndCreateShareLink[​](#simulateuseroperationwithtenderlyandcreatesharelink "Direct link to 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[​](#source-code-6 "Direct link to Source code")

[simulateUserOperationWithTenderlyAndCreateShareLink](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utilsTenderly.ts#L82)

### simulateUserOperationCallDataWithTenderlyAndCreateShareLink[​](#simulateuseroperationcalldatawithtenderlyandcreatesharelink "Direct link to 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[​](#source-code-7 "Direct link to Source code")

[simulateUserOperationCallDataWithTenderlyAndCreateShareLink](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utilsTenderly.ts#L376)

### simulateSenderCallDataWithTenderlyAndCreateShareLink[​](#simulatesendercalldatawithtenderlyandcreatesharelink "Direct link to 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[​](#source-code-8 "Direct link to Source code")

[simulateSenderCallDataWithTenderlyAndCreateShareLink](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utilsTenderly.ts#L596)

## Multicall utils[​](#multicall-utils "Direct link to Multicall utils")

### encodeMultiSendCallData[​](#encodemultisendcalldata "Direct link to 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[​](#source-code-9 "Direct link to Source code")

[encodeMultiSendCallData](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/account/Safe/multisend.ts#L26)

### decodeMultiSendCallData[​](#decodemultisendcalldata "Direct link to 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[​](#source-code-10 "Direct link to Source code")

[decodeMultiSendCallData](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/account/Safe/multisend.ts#L36)

## Generic Ethereum utils[​](#generic-ethereum-utils "Direct link to Generic Ethereum utils")

### fetchGasPrice[​](#fetchgasprice "Direct link to fetchGasPrice")

Deprecated in `v0.3.8`. Use `JsonRpcNode#getFeeData` instead.

migration.ts

```
import { GasOption, JsonRpcNode } from "abstractionkit";



const node = new JsonRpcNode("https://ethereum-sepolia-rpc.publicnode.com");

const [maxFeePerGas, maxPriorityFeePerGas] = await node.getFeeData(GasOption.Medium);
```

### createCallData[​](#createcalldata "Direct link to 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", // transfer(address,uint256) selector

  ["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[​](#source-code-11 "Direct link to Source code")

[createCallData](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L474)

### getFunctionSelector[​](#getfunctionselector "Direct link to 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)");

// Returns "0xa9059cbb"
```

| 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[​](#source-code-12 "Direct link to Source code")

[getFunctionSelector](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L567)

### sendJsonRpcRequest[​](#sendjsonrpcrequest "Direct link to 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[​](#source-code-13 "Direct link to Source code")

[sendJsonRpcRequest](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils.ts#L514)

### sendEthCallRequest[​](#sendethcallrequest "Direct link to sendEthCallRequest")

Deprecated in `v0.3.8`. Use `JsonRpcNode#call` instead.

example.ts

```
import { JsonRpcNode } from "abstractionkit";



const node = new JsonRpcNode("https://ethereum-sepolia-rpc.publicnode.com");

const result = await node.call({

  to: "0xContractAddress",

  data: "0xCallData",

});
```

#### Source code[​](#source-code-14 "Direct link to Source code")

[JsonRpcNode.call](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/transport/JsonRpcNode.ts#L163)

### sendEthGetCodeRequest[​](#sendethgetcoderequest "Direct link to sendEthGetCodeRequest")

Deprecated in `v0.3.8`. Use `JsonRpcNode#getCode` instead.

example.ts

```
import { JsonRpcNode } from "abstractionkit";



const node = new JsonRpcNode("https://ethereum-sepolia-rpc.publicnode.com");

const code = await node.getCode("0xContractAddress");
```

#### Source code[​](#source-code-15 "Direct link to Source code")

[JsonRpcNode.getCode](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/transport/JsonRpcNode.ts#L137)

### getDelegatedAddress[​](#getdelegatedaddress "Direct link to getDelegatedAddress")

Deprecated in `v0.3.8`. Use `JsonRpcNode#getDelegatedAddress` instead.

migration.ts

```
import { JsonRpcNode } from "abstractionkit";



const node = new JsonRpcNode("https://ethereum-sepolia-rpc.publicnode.com");

const delegatee = await node.getDelegatedAddress("0xYourEOAAddress");



if (delegatee) {

  console.log("Delegated to:", delegatee);

} else {

  console.log("Not delegated");

}
```

## EIP-7702 Utilities[​](#eip-7702-utilities "Direct link to EIP-7702 Utilities")

### createAndSignEip7702DelegationAuthorization[​](#createandsigneip7702delegationauthorization "Direct link to 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";



// With a private key (synchronous)

const authorization = createAndSignEip7702DelegationAuthorization(

  11155111n,

  "0xDelegateeContractAddress",

  0n,

  "0xYourPrivateKey"

);



// With an async signer callback

const authorization = await createAndSignEip7702DelegationAuthorization(

  11155111n,

  "0xDelegateeContractAddress",

  0n,

  async (hash) => {

    // Sign the hash using your preferred method

    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[​](#source-code-16 "Direct link to Source code")

[createAndSignEip7702DelegationAuthorization](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils7702.ts#L137)

### createRevokeDelegationAuthorization[​](#createrevokedelegationauthorization "Direct link to 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[​](#source-code-17 "Direct link to Source code")

[createRevokeDelegationAuthorization](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils7702.ts#L192)

### createEip7702DelegationAuthorizationHash[​](#createeip7702delegationauthorizationhash "Direct link to 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[​](#source-code-18 "Direct link to Source code")

[createEip7702DelegationAuthorizationHash](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils7702.ts#L209)

### createAndSignEip7702RawTransaction[​](#createandsigneip7702rawtransaction "Direct link to 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,       // chainId

  0n,              // nonce

  2000000000n,     // maxPriorityFeePerGas

  20000000000n,    // maxFeePerGas

  21000n,          // gasLimit

  "0xDestination", // destination

  0n,              // value

  "0x",            // data

  [],              // accessList

  [authorization], // authorizationList

  "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[​](#source-code-19 "Direct link to Source code")

[createAndSignEip7702RawTransaction](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils7702.ts#L255)

### createEip7702TransactionHash[​](#createeip7702transactionhash "Direct link to 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,       // chainId

  0n,              // nonce

  2000000000n,     // maxPriorityFeePerGas

  20000000000n,    // maxFeePerGas

  21000n,          // gasLimit

  "0xDestination", // destination

  0n,              // value

  "0x",            // data

  [],              // accessList

  [authorization]  // authorizationList

);
```

| 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[​](#source-code-20 "Direct link to Source code")

[createEip7702TransactionHash](https://github.com/candidelabs/abstractionkit/blob/v0.3.8/src/utils7702.ts#L319)
