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.
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: ASignerorWalletinstance for signing and sending transactions.Returns: A newPaymasterinstance.
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- ASignerorWalletinstance for signing transactions.paymasterType: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
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:Human-Readable fragment - string which resembles a Solidity signature and is introduced in this blog entry. For example,
function balanceOf(address) view returns (uint).Parsed JSON fragment - Fragment instances - JavaScript Object desribed in the Solidity documentation.
args:any[](optional) - An array of arguments for the function call.overrides:PaymasterOverrides(optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)Returns: ATransactionRequestobject populated with the transaction data.
getPaymasterCustomData
Generates the PaymasterParams object that will be passed to the transaction that's using a paymaster.
paymasterOptions:PaymasterOptions(optional) - An object containing options for the Paymaster (e.g., innerInput, minimalAllowance).Returns: APaymasterParamsobject.
sendPaymasterTransaction
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:Human-Readable fragment - string which resembles a Solidity signature and is introduced in this blog entry. For example,
function balanceOf(address) view returns (uint).Parsed JSON fragment - Fragment instances - JavaScript Object desribed in the Solidity documentation.
args:any[](optional) - An array of arguments for the function call.overrides:PaymasterOverrides(optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)Returns: ATransactionResponseobject.
sendTransaction
Sends a populated TransactionRequest object using the Paymaster.
tx: TheTransactionRequestobject to send.Returns: ATransactionResponseobject.
getBalance
Gets the balance of the Paymaster contract.
Returns: The balance of the Paymaster contract as aBigNumberishvalue.
estimateGas
Estimates the gas required for a transaction. Especially tailored for Paymaster paymaster needs.
tx: TheTransactionRequestobject for which to estimate the gas.Returns: The estimated gas limit as aBigNumberishvalue.
getPaymasterContract
Gets an instance of the ERC20Paymaster or SponsoredPaymaster contract, depending on the paymasterType.
Returns: An instance of the(ethers.Contract).
addRestriction
Adds a restriction to the Paymaster.
address:Address- The address of the restriction contract to add.Returns: AContractTransactionResponseobject.
getRestrictions
Gets the list of restriction contract addresses added to the Paymaster.
Returns: An array of restriction contract addresses.
removeRestriction
Removes a restriction contract from the Paymaster.
address:Address- The address of the restriction contract to remove.Returns: AContractTransactionResponseobject.
checkTransactionEligibility
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:Human-Readable fragment - string which resembles a Solidity signature and is introduced in this blog entry. For example,
function balanceOf(address) view returns (uint).Parsed JSON fragment - Fragment instances - JavaScript Object desribed in the Solidity documentation.
args:any[](optional) - An array of arguments for the function call.overrides:PaymasterOverrides(optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)Returns:trueif the transaction is eligible,falseotherwise.
getMinimalAllowance
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:Human-Readable fragment - string which resembles a Solidity signature and is introduced in this blog entry. For example,
function balanceOf(address) view returns (uint).Parsed JSON fragment - Fragment instances - JavaScript Object desribed in the Solidity documentation.
args:any[](optional) - An array of arguments for the function call.overrides:PaymasterOverrides(optional)- An object containing overrides for the transaction (e.g., to, value, data, customData, gasLimit, maxFeePerGas, maxPriorityFeePerGas)Returns: The minimal allowance as aBigNumberishvalue.
Last updated