prepareForPaymaster
to delegate the payment of the gas fees to a paymaster set in the transaction,
at which point the paymaster will validate and pay for the transaction.
Get Started with Paymasters
Use our example repositories to quickly get started building paymasters. Or follow our video tutorial for a step-by-step guide to building a smart contract wallet.YouTube Video: Build a Paymaster smart contract on Abstract
IPaymaster Interface
TheIPaymaster
interface defines the mandatory functions that a paymaster must implement to be
compatible with Abstract. View source code ↗.
First, install the system contracts library:
IPaymaster
interface in your smart contract:
validateAndPayForPaymasterTransaction
This function is called to perform 2 actions:- Validate (determine whether or not to sponsor the gas fees for) the transaction.
- Pay the gas fee to the bootloader for the transaction. This method must send at least
tx.gasprice * tx.gasLimit
to the bootloader. Learn more about gas fees and gas refunds.
magic = PAYMASTER_VALIDATION_SUCCESS_MAGIC
.
Optionally, you can also provide context
that is provided to the postTransaction
function
called after the transaction is executed.
postTransaction
This function is optional and is called after the transaction is executed. There is no guarantee this method will be called if the transaction fails without of gas
error.
Sending Transactions with a Paymaster
Use EIP-712 formatted transactions to submit transactions with a paymaster set. You must specify acustomData
object containing a valid paymasterParams
object.
View example zksync-ethers script
View example zksync-ethers script
Paymaster Flows
Below are two example flows for paymasters you can use as a reference to build your own paymaster:- General Paymaster Flow: Showcases a minimal paymaster that sponsors all transactions.
- Approval-Based Paymaster Flow: Showcases how users can pay for gas fees with an ERC-20 token.
General Paymaster Implementation
View the source code for an example general paymaster flow implementation.
Approval Paymaster Implementation
View the source code for an example approval-based paymaster flow
implementation.