What are Paymasters?

One of ERC-4337's key components is the Paymaster, which enables third-party mechanisms to pay for transactions on behalf of users.

The world of blockchain is constantly evolving, and with each new development, it becomes easier for developers to build great experiences for users. One such development is EIP-4337, a standard for account abstraction in the Ethereum blockchain. In this article, we'll be focusing on the Paymaster component of EIP-4337 and how it operates within the framework.

Paymasters in EIP-4337 are smart contract accounts that facilitate transaction sponsorship by allowing third-party-designed mechanisms to pay for transactions. These are often called gasless transactions. This is important because without paymasters, users need to have a blockchain's native token in their account to pay for transactions. There would be no possibility to sponsor transaction fees for users or allow them to accept network fees in some EIP-20 token.

The paymaster scheme in EIP-4337 allows a contract to pay on users' behalf under arbitrary conditions. This opens up a whole new level of possibilities for the implementation of transaction sponsorship mechanisms in the Ethereum blockchain.

Sponsoring Transactions

There are many cases where an app may want to pay for transactions for users. For example, a user may be generating NFT content on a platform that will earn royalties on sales, or a checkout app may accept a credit card for payment for on-chain goods that need to be transfered. Whatever the case may be, EIP-4337 Paymasters make it possible.

An EIP-4337 Paymaster is a special kind of smart contract account that can pay gas for others. The paymaster contract needs some sort of verification logic for each transaction, which is checked when the transaction is made.

Probably the simplest example of a paymaster is Stackup's Plug-n-Play Paymaster. This service gives you an API key that, when called, will sponsor transactions and bill your Stackup account. Under the hood, Stackup's paymaster simply checks if a transaction is valid and signs the transaction if it approves. On-chain, the EntryPoint contract takes care of the rest.

Paying Gas With ERC-20 Tokens

With EIP-4337 paymasters, even ERC-20 token paymasters can secure a guarantee that they would only need to pay if the user pays them. The paymaster contract can check for sufficient approved ERC-20 balance in the "validatePaymasterUserOp" method, and then extract it with "transferFrom" in the "postOp" call.

But what happens if a user changes their behavior after a block is confirmed? Well, with EIP-4337 paymasters, the inner "postOp" will fail and revert the execution, and the outer "postOp" can extract payment. This helps to mitigate the risk of getting griefed by malicious users.

EIP-4337 Paymasters provide a powerful solution for transaction sponsorship in the Ethereum blockchain. They allow for passive payment on behalf of users, secure payment guarantees, and mitigate the risk of getting griefed. With its potential for innovation and its commitment to security, it's clear that EIP-4337 is a standard that developers should be paying attention to.

You can pay gas with ERC-20 tokens using Stackup's paymaster API.

The Paymaster Contract component of EIP-4337 is a powerful tool for transaction sponsorship in the Ethereum blockchain. Its potential for innovation and its commitment to security make it an important standard for developers to consider.