Paymaster Overview
Paymasters in the ZKsync ecosystem represent a groundbreaking approach to handling transaction fees. They are special accounts designed to subsidize transaction costs for other accounts, potentially making certain transactions free for end-users. This feature is particularly useful for dApp developers looking to improve their platform’s accessibility and user experience by covering transaction fees on behalf of their users.
How Paymasters Work
Paymasters are smart contracts that implement the IPaymaster
interface. They are designed to be used in conjunction with the ZKsync network’s transaction processing mechanism. When a transaction is sent from an account, the paymaster is specified in the transaction’s metadata. The paymaster is then responsible for paying the transaction fee and any other costs associated with the transaction.
How to interact with a Paymaster using Foundry
As of right now, the ways to interact with a paymaster contract using Foundry are using cast send
, forge create
or with the use of the zkUsePaymaster
cheatcode.
Using cast send
cast send
signs and publishes a transaction. The documentation can be found here.
To pair this with a paymaster contract, you need to specify the paymaster address and the encoded paymaster input in the command.
The flags for this are:
--zk-paymaster-address
The address where the paymaster contract is deployed.
--zk-paymaster-input
The encoded input for the paymaster contract. This depends on the paymaster contract implementation.
To encode the paymaster input, you can use the cast calldata
command which can be found here.
cast send 0xdb8bA5F5DfB1636361d2fE851d7D3ed93acfc487 "increment()" --rpc-url https://sepolia.era.zksync.dev --private-key <your-private-key> --zk-paymaster-address 0x3cB2b87D10Ac01736A65688F3e0Fb1b070B3eeA3 --zk-paymaster-input $(cast calldata "approvalBased(address,uint256,bytes)" 0x31c43ac5e6A0fe62954B9056441b0A214722516e 1000000000000000000 "0x")
Using forge create
forge create
is a command-line tool for deploying smart contracts using the Foundry framework. The documentation can be found here.
To deploy a paymaster contract using forge create
, you need to specify the paymaster contract address in the command.
The flags for this are:
--zk-paymaster-address
The address where the paymaster contract is deployed.
--zk-paymaster-input
The encoded input for the paymaster contract. This depends on the paymaster contract implementation.
To encode the paymaster input, you can use the cast calldata
command also which can be found here.
forge create Greeter.sol:Greeter --rpc-url "https://sepolia.era.zksync.dev" --private-key <your-private-key> --zksync --zk-paymaster-address 0x3cB2b87D10Ac01736A65688F3e0Fb1b070B3eeA3 --zk-paymaster-input $(cast calldata "approvalBased(address,uint256,bytes)" 0x31c43ac5e6A0fe62954B9056441b0A214722516e 1 "0x")
Also, see the ZKsync Paymaster Documentation for more information.