Paymasters
Learn how paymasters are built following the IPaymaster standard on Abstract.
Paymasters are smart contracts that pay for the gas fees of transactions on behalf of other accounts.
All paymasters must implement the
IPaymaster interface. As outlined in the transaction flow,
after the smart contract wallet validates and executes the transaction,
it can optionally call 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
The IPaymaster
interface defines the mandatory functions that a paymaster must implement to be
compatible with Abstract. View source code ↗.
First, install the system contracts library:
Then, import and implement the 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.
To validate (i.e. agree to sponsor the gas fee for) a transaction, this function should
return 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 with out of gas
error.
Sending Transactions with a Paymaster
Use EIP-712 formatted transactions to submit transactions with a paymaster set.
You must specify a customData
object containing a valid paymasterParams
object.
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.
Smart Contract References
Was this page helpful?