txSync SDK
HomeBlogProjectsCreate ZK Chains
  • 👋Introduction
  • 🚀Getting Started
    • Installation Guide
    • Quick Start Guide
  • 🛠️SDKs
    • 📦@txfusion/txsync-sdk
      • 🚀 Quick start
      • 📝 API
        • Paymaster
        • Restrictions
      • 🧑‍🍳 Examples
      • 🤝 Contributing
    • 📦@txfusion/txsync-viem
      • 🚀 Quick start
      • 📝 API
        • Paymaster
        • Extensions
      • 🧑‍🍳 Examples
      • 🤝 Contributing
  • 🔌Product Integration
    • Portal
    • Bridge
    • Tsuko
    • Visor
    • ZK Chains
    • Playground
Powered by GitBook
On this page
  • getPaymaster
  • Paymaster
  • Constructor
  • populatePaymasterTransaction
  • getPaymasterCustomData
  • sendPaymasterTransaction
  • sendTransaction
  • getBalance
  • estimateGas
  • getPaymasterContract
  • addRestriction
  • getRestrictions
  • removeRestriction
  • checkTransactionEligibility
  • getMinimalAllowance
  1. SDKs
  2. @txfusion/txsync-sdk
  3. 📝 API

Paymaster

The Paymaster class is a utility class that provides methods for interacting with Paymaster contracts on the zkSync network. It supports two types of Paymasters: ERC20Paymaster and SponsoredPaymaster.

Previous📝 APINextRestrictions

Last updated 11 months ago

To call the methods of the Paymaster class, we need to first get the paymaster object.

getPaymaster

async function getPaymaster(address: Address, runner: Signer | Wallet): Promise<Paymaster>

Creates a new instance of the Paymaster class based on the provided Paymaster contract address.

  • address: Address: The address of the Paymaster contract.

  • runner: Signer | Wallet: A Signer or Wallet instance for signing and sending transactions.

  • Returns: A new Paymaster instance.

Paymaster

The Paymaster class is a utility class that provides methods for interacting with Paymaster contracts on the zkSync network. It supports two types of Paymasters: ERC20Paymaster and SponsoredPaymaster.

Constructor

constructor(address: Address, runner: Signer | Wallet, paymasterType: PaymasterType, chainId: string, token?: Address)
  • address: Address - The address of the Paymaster contract.

  • runner: Signer | Wallet - A Signer or Wallet instance for signing transactions.

  • paymasterType: - type of Paymaster (ERC20Paymaster or SponsoredPaymaster).

  • chainId: string - The ID of the chain the Paymaster contract is deployed on.

  • token: Address (optional) - The address of the ERC20 token used by the ERC20Paymaster.

populatePaymasterTransaction

async populatePaymasterTransaction(contractAddress: Address, functionToCall: InterfaceAbi, args?: any[], overrides?: PaymasterOverrides): Promise<TransactionRequest>

Populates a TransactionRequest object with the necessary data to call a function on a contract using the Paymaster.

  • contractAddress: Address - The address of the contract to call.

  • functionToCall: ethers.InterfaceAbi - The definition of the function to call. Can be:

  • args: any[] (optional) - An array of arguments for the function call.

  • Returns: A TransactionRequest object populated with the transaction data.

getPaymasterCustomData

getPaymasterCustomData(paymasterOptions?: PaymasterOptions): PaymasterParams

Generates the PaymasterParams object that will be passed to the transaction that's using a paymaster.

  • Returns: A PaymasterParams object.

sendPaymasterTransaction

async sendPaymasterTransaction(contractAddress: Address, functionToCall: InterfaceAbi, args: any[] = [], overrides?: PaymasterOverrides): Promise<TransactionResponse>

Populates and sends a transaction using the Paymaster.

  • contractAddress: Address - The address of the contract to call.

  • functionToCall: ethers.InterfaceAbi - The definition of the function to call. Can be:

  • args: any[] (optional) - An array of arguments for the function call.

  • Returns: A TransactionResponse object.

sendTransaction

async sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>

Sends a populated TransactionRequest object using the Paymaster.

  • tx: The TransactionRequest object to send.

  • Returns: A TransactionResponse object.

getBalance

async getBalance(): Promise<BigNumberish>

Gets the balance of the Paymaster contract.

  • Returns: The balance of the Paymaster contract as a BigNumberish value.

estimateGas

async estimateGas(tx: TransactionRequest): Promise<BigNumberish>

Estimates the gas required for a transaction. Especially tailored for Paymaster paymaster needs.

  • tx: The TransactionRequest object for which to estimate the gas.

  • Returns: The estimated gas limit as a BigNumberish value.

getPaymasterContract

getPaymasterContract(): ERC20Paymaster | SponsoredPaymaster
  • Returns: An instance of the (ethers.Contract).

addRestriction

async addRestriction(address: Address): Promise<ContractTransactionResponse>

Adds a restriction to the Paymaster.

  • address: Address - The address of the restriction contract to add.

  • Returns: A ContractTransactionResponse object.

getRestrictions

async getRestrictions(): Promise<string[]>

Gets the list of restriction contract addresses added to the Paymaster.

  • Returns: An array of restriction contract addresses.

removeRestriction

async removeRestriction(address: Address): Promise<ContractTransactionResponse>

Removes a restriction contract from the Paymaster.

  • address: Address - The address of the restriction contract to remove.

  • Returns: A ContractTransactionResponse object.

checkTransactionEligibility

async checkTransactionEligibility(contractAddress: Address, functionToCall: InterfaceAbi, args: any[] = [], overrides?: PaymasterOverrides): Promise<boolean>

Checks if a transaction is eligible to be paid for by the Paymaster, based on the added restrictions.

  • contractAddress: Address - The address of the contract to call.

  • functionToCall: ethers.InterfaceAbi - The definition of the function to call. Can be:

  • args: any[] (optional) - An array of arguments for the function call.

  • Returns: true if the transaction is eligible, false otherwise.

getMinimalAllowance

async getMinimalAllowance(contractAddress: Address, functionToCall: InterfaceAbi, args?: any[], overrides?: PaymasterOverrides): Promise<BigNumberish>

Calculates the minimal allowance required for an ERC20Paymaster to pay for a transaction.

  • contractAddress: Address - The address of the contract to call.

  • functionToCall: ethers.InterfaceAbi - The definition of the function to call. Can be:

  • args: any[] (optional) - An array of arguments for the function call.

  • Returns: The minimal allowance as a BigNumberish value.

Human-Readable fragment - string which resembles a Solidity signature and is introduced in . For example, function balanceOf(address) view returns (uint).

Parsed JSON fragment - instances - JavaScript Object desribed in the .

overrides: (optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)

paymasterOptions: (optional) - An object containing options for the Paymaster (e.g., innerInput, minimalAllowance).

Human-Readable fragment - string which resembles a Solidity signature and is introduced in . For example, function balanceOf(address) view returns (uint).

Parsed JSON fragment - instances - JavaScript Object desribed in the .

overrides: (optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)

Gets an instance of the ERC20Paymaster or SponsoredPaymaster contract, depending on the .

Human-Readable fragment - string which resembles a Solidity signature and is introduced in . For example, function balanceOf(address) view returns (uint).

Parsed JSON fragment - instances - JavaScript Object desribed in the .

overrides: (optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)

Human-Readable fragment - string which resembles a Solidity signature and is introduced in . For example, function balanceOf(address) view returns (uint).

Parsed JSON fragment - instances - JavaScript Object desribed in the .

overrides: (optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)

🛠️
📦
PaymasterType
this blog entry
Fragment
Solidity documentation
PaymasterOverrides
PaymasterOptions
this blog entry
Fragment
Solidity documentation
PaymasterOverrides
paymasterType
this blog entry
Fragment
Solidity documentation
PaymasterOverrides
this blog entry
Fragment
Solidity documentation
PaymasterOverrides