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
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
: ASigner
orWallet
instance for signing and sending transactions.Returns
: A newPaymaster
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
address
:Address
- The address of the Paymaster contract.runner
:Signer
|Wallet
- ASigner
orWallet
instance 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
: ATransactionRequest
object 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
: APaymasterParams
object.
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
: ATransactionResponse
object.
sendTransaction
Sends a populated TransactionRequest
object using the Paymaster.
tx
: TheTransactionRequest
object to send.Returns
: ATransactionResponse
object.
getBalance
Gets the balance of the Paymaster contract.
Returns
: The balance of the Paymaster contract as aBigNumberish
value.
estimateGas
Estimates the gas required for a transaction. Especially tailored for Paymaster paymaster needs.
tx
: TheTransactionRequest
object for which to estimate the gas.Returns
: The estimated gas limit as aBigNumberish
value.
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
: AContractTransactionResponse
object.
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
: AContractTransactionResponse
object.
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
:true
if the transaction is eligible,false
otherwise.
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 aBigNumberish
value.
Last updated