Paymaster Utilities


Paymaster Utilities

The paymaster utilities libraryopen in new window contains essential utilities for using paymasters on zkSync Era.

Contract interfaces

Constant ABI definition for the Paymaster Flow Interfaceopen in new window.

export const PAYMASTER_FLOW_ABI = new ethers.Interface(require("../abi/IPaymasterFlow.json"));

Functions

getApprovalBasedPaymasterInput

Returns encoded input for an approval-based paymaster.

Inputs

ParameterTypeDescription
paymasterInputApprovalBasedPaymasterInputThe input data to the paymaster.
export function getApprovalBasedPaymasterInput(paymasterInput: ApprovalBasedPaymasterInput): BytesLike;

getGeneralPaymasterInput

As above but for general-based paymaster.

Inputs

ParameterTypeDescription
paymasterInputGeneralPaymasterInputThe input data to the paymaster.
export function getGeneralPaymasterInput(paymasterInput: GeneralPaymasterInput): BytesLike;

getPaymasterParams

Returns a correctly-formed paymasterParams object for common paymaster flows.

Inputs

ParameterTypeDescription
paymasterAddressAddressThe non-zero paymaster address.
paymasterInputPaymasterInputThe input data to the paymaster.
export function getPaymasterParams(paymasterAddress: Address, paymasterInput: PaymasterInput): PaymasterParams;

Find out more about the PaymasterInput type.

Examples

Creating General paymaster parameters.

const paymasterAddress = "0x0a67078A35745947A37A552174aFe724D8180c25";
const paymasterParams = utils.getPaymasterParams(paymasterAddress, {
  type: "General",
  innerInput: new Uint8Array(),
});

Creating ApprovalBased paymaster parameters.

const result = utils.getPaymasterParams("0x0a67078A35745947A37A552174aFe724D8180c25", {
  type: "ApprovalBased",
  token: "0x65C899B5fb8Eb9ae4da51D67E1fc417c7CB7e964",
  minimalAllowance: BigInt(1),
  innerInput: new Uint8Array(),
});