Sponsored Transactions
Sponsored transactions is an umbrella term for multiple methods of utilizing ERC 7677 paymasters. There are 2 types of paymasters that AppKit supports:
- ERC 20 Paymasters
- Verifying Paymasters
This approach simplifies blockchain interactions by enabling users to perform actions without directly handling transaction fees, which are instead paid by the dApp. This concept is particularly beneficial for attracting new users, as it removes the need to understand complex wallet mechanics or hold cryptocurrency for gas fees, making the overall experience more intuitive and accessible.
By absorbing these costs, dApps can offer a smoother onboarding experience.
ERC 20 Paymasters
ERC 20 paymasters allow end users (smart account wallets) to cover transaction fees without using a network's native gas token. In essence, this gives the ability to cover transaction fees using ERC 20 tokens like USDC.
Verifying Paymasters
Verifying Paymasters are more involved, in that they are typically used alongside some policies that determine whether or not a transaction's entire gas fee will be covered by the paymaster. For example, only sponsor transactions that interact with a specific smart account, accessing a particular method.
Using A Paymaster URL
Using a paymaster as a dapp involves leveraging the capabilities
field present in EIP 5792 calls.
Setting a field like so:
sendCalls({
calls: ...callsToSend,
capabilities: {
paymasterService: {
url: paymasterServiceUrl,
context?: {
// Any additional context
}
}
}
})
Where calls
is an array of 5792 calls to send, paymasterServiceUrl
is a
string containing the paymaster URL and context
is an optional configuration object for the paymaster.
The context
field is paymaster specific and it might be required depending on the Paymaster implementation.
Naturally, since interacting with paymasters requires using sendCalls
as
opposed to writeContractAsync
or similar, this will require code changes.
A general guide on adapting existing code can be found here
As a Dapp, that is all that is required to take advantage of verifying paymasters. The rest would be handled wallet side. If the calls match the criteria set in the paymaster's policy, then the calls' gas would be sponsored. However, if it does not, then the transaction would be cancelled.
Example implementation can be found here.
A Note on ERC20 Paymaster integration
As of right now, ERC20 paymasters would require to provide a context on the tokens to use for gas payment. How to get this context is not yet standardized and is up to the dapp to integrate with their provider in order to fetch available tokens and other required implementation-specific context data.
A Note on Wallets
As of right now, not many smart account wallets support paymasters, however AppKit's embedded smart account covers full compatibility with ERC7677 paymasters.