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 transaction:

const transactionRequest: types.TransactionRequest = {
  to: "<RECEIVER_ADDRESS>",
  value: 1,
  customData: {
    paymasterParams: getPaymasterParams("<PAYMASTER_ADDRESS>", {
      innerInput: new Uint8Array(),
      minimalAllowance: 1n,
      token: "<TOKEN_ADDRESS>",
      type: "ApprovalBased",
    }),
  },
};
const response: types.PriorityOpResponse =
  await wallet.signAndSend(transactionRequest);

Made with ❤️ by the ZKsync Community