Bundler Methods
Imports needed for these methods:
import { IBundler, Bundler } from "@abstraxn/bundler";
import { ChainId } from "@abstraxn/core-types";
const abstraxnBundler: IBundler = new Bundler({
bundlerUrl: "",
chainId: ChainId.POLYGON_MAINNET,
entryPointAddress: "",
});
Following are the methods that can be call on bundler instance
estimateUserOpGas
This method is used to estimate gas for the userOp. Gas estimation for the userOp is done using this method. For a given UserOperation, it produces estimates for preVerificationGas, verificationGasLimit, and callGasLimit. It requires sending a dummy signature through userOp (for example, one that is the right length and format).
Usage
const userOpGasResponse: UserOpGasResponse = await abstraxnBundler.estimateUserOpGas(userOp);
Parameters
- userOp(
<UserOperation>
, required): A UserOperation object representing the user's request that needs to be processed.
Returns
-
userOpGasResponse(
Promise<UserOpGasResponse>
): It returns an object containing the following gas values.type UserOpGasResponse = {
preVerificationGas: string;
verificationGasLimit: string;
callGasLimit: string;
maxPriorityFeePerGas: string;
maxFeePerGas: string;
};
sendUserOp
This method is used to execute the userOp.
Usage
const userOpGasResponse: UserOpGasResponse = await abstraxnBundler.sendUserOp(
userOp
);
Parameters
- userOp(
<UserOperation>
, required): A UserOperation object representing the user's request that needs to be processed. - simulationParam(SimulationType): The simulationType enum can be of two types:
validation
which will only simulate the validation phase, checks if user op is valid but does not check if execution will succeed. By default this flag is set to validation.validation_and_execution
checks if user op is valid and if user op execution will succeed.
Returns
-
userOpResponse(
Promise<UserOpResponse>
): It returns an object containing the userOpHash and other methods.wait()
method waits for the receipt until the transaction is mined.waitForTxHash()
returns transactionHash identifier (not userOpHash) and you can later watch for receipt on your own.type UserOpResponse = {
userOpHash: string;
wait(_confirmations?: number): Promise<UserOpReceipt>;
waitForTxHash(): Promise<UserOpStatus>;
};
getUserOpReceipt
After using sendUserOp
you will receive a userOpResponse
which contains a string called userOpHash
.
Using this userOpHash
you can fetch the userOpReceipt
which verifies that your userOp
was handled on chain as a transaction.
Usage
const userOpReceipt = await abstraxnBundler.getUserOpReceipt("0x....");
Parameters
- userOpHash(
string
, required): user operation hash.
returns
-
userOpReceipt(
Promise<UserOpReceipt>
): The full UserOpReceipt object type is shown below:type UserOpReceipt = {
userOpHash: string;
entryPoint: string;
sender: string;
nonce: number;
paymaster: string;
actualGasCost: BigNumber;
actualGasUsed: BigNumber;
success: boolean;
reason: string;
logs: Array<ethers.providers.Log>; // The logs generated by this UserOperation (not including logs of other UserOperations in the same bundle)
receipt: ethers.providers.TransactionReceipt;
};
getUserOpByHash
Using the userOpHash
you can fetch the original userOp
that was created with this hash.
Usage
const userOp = await abstraxnBundler.getUserOpByHash("0x...");
Parameters
- userOpHash(
string
, required): user operation hash.
returns
-
userOp(
Promise<UserOpByHashResponse>
) : The userOperation will contain the following values:type BytesLike = Bytes | string;
type UserOpByHashResponse = UserOperationStruct & {
transactionHash: string;
blockNumber: number;
blockHash: string;
entryPoint: string;
};
type UserOperationStruct = {
callData: BytesLike;
callGasLimit?: number | bigint | `0x${string}`;
initCode: BytesLike;
maxFeePerGas?: number | bigint | `0x${string}`;
maxPriorityFeePerGas?: number | bigint | `0x${string}`;
nonce: number | bigint | `0x${string}`;
paymasterAndData: BytesLike;
preVerificationGas?: number | bigint | `0x${string}`;
sender: string;
signature: BytesLike;
verificationGasLimit?: number | bigint | `0x${string}`;
};