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
  • getPaymasterCustomData
  • sendPaymasterTransaction
  • getBalance
  • estimateGas
  • getPaymasterContract
  • addExtension
  • getExtensions
  • removeExtension
  1. SDKs
  2. @txfusion/txsync-viem
  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📝 APINextExtensions

Last updated 9 months ago

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

getPaymaster

async function getPaymaster(address: Address, walletClient: WalletClient, publicClient: PublicClient): 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.

  • walletClient: WalletClient instance for signing and sending transactions.

  • publicClient: PublicClient public instance for getting public functions

  • 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, walletClient: WalletClient, publicClient: PublicClient, paymasterType: PaymasterType, chainId: ChainId, token?: Address)
  • address: Address - The address of the Paymaster contract.

  • walletClient: WalletClient instance for signing transactions.

  • publicClient: PublicClient instance for getting public functions

  • 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.

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

sync sendPaymasterTransaction(address: Address, abi: Abi | readonly unknown[], functionName: string, args: any[] = [], overrides?: PaymasterOverrides): Promise<Address>

Populates and sends a transaction using the Paymaster.

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

  • abi: Abi | readonly unknown[] - The ABI of the contract to call

  • functionName: string - The name of the function to call

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

  • Returns: A hash object.

getBalance

async getBalance(): Promise<bigint>

Gets the balance of the Paymaster contract.

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

estimateGas

async estimateGas(address: Address, abi: Abi | readonly unknown[], functionName: string, args?: any[], overrides?: PaymasterOverrides): Promise<bigint>

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

  • address: Address - The address of the contract to call for which to estimate the gas.

  • abi: Abi | readonly unknown[] - The ABI of the contract to call for which to estimate the gas.

  • functionName: string - The name of the function to call for gas estimation.

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

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

getPaymasterContract

getPaymasterContract(): ERC20PaymasterContract | SponsoredPaymasterContract
  • Returns: An instance of the paymaster contract in ERC20PaymasterContract or SponsoredPaymasterContract type.

addExtension

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

Adds an extension to the Paymaster.

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

  • Returns: A hash of the extension.

getExtensions

async getExtensions(): Promise<string[]>

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

  • Returns: An array of extension contract addresses.

removeExtension

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

Removes an extension contract from the Paymaster.

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

  • Returns: A hash of the transaction object.

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

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

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 .

🛠️
📦
PaymasterType
PaymasterOptions
PaymasterOverrides
PaymasterOverrides
paymasterType