Web3JS

Paymasters

Use a paymaster to pay transaction fees

Paymasters are specialized accounts that are designed to subsidize transaction costs and can be used to make transactions free for end-users.

Use a paymaster to pay transaction fees

To use a paymaster to subsidize the transaction costs of any transaction made with the Web3.js plugin for ZKsync, add a paymasterParams property of type PaymasterParams to the transaction's custom data. To generate an object of type PaymasterParams, use the getPaymasterParams helper function, which expects two parameters: the address of the paymaster account and an object that implements either the ApprovalBasedPaymasterInput interface (for approval-based paymaster flows) or the GeneralPaymasterInput interface (for general paymaster flows).

The following code snippet demonstrates using an approval-based paymaster to cover the fees of a deposit transaction:

const tx: types.PriorityOpResponse = await wallet.deposit({
  token: "<TOKEN_ADDRESS>",
  to: "<RECEIVER_ADDRESS>",
  amount: 2_000_000_000n,
  refundRecipient: wallet.getAddress(),
  customData: {
    paymasterParams: getPaymasterParams("<PAYMASTER_ADDRESS>", {
      innerInput: new Uint8Array(),
      minimalAllowance: 1n,
      token: "<TOKEN_ADDRESS>",
      type: "ApprovalBased",
    }),
  },
});

Made with ❤️ by the ZKsync Community