Interacting with the Gasless Paymaster
Interacting with the Gasless Paymaster
Now that we have successfully deployed and validated the Gasless Paymaster, the next step is to demonstrate
how users can interact with it to execute transactions without paying gas fees using cast send
and forge create
.
Sending a Gasless Transaction with cast send
The cast send
command allows us to sign and broadcast transactions, when used alongside ZKsync paymaster flags we can
cover gas fees by the paymaster instead of the sender.
Required Flags
To execute a transaction using a paymaster, we need to specify:
--zk-paymaster-address
→ The address of the deployed paymaster contract.--zk-paymaster-input
→ The encoded input required for the paymaster contract to process the transaction.
Encoding the Paymaster Input
To properly encode the paymaster input, we use the cast calldata
command:
cast calldata "general(bytes)" "0x"
Executing a Transaction with the GaslessPaymaster
Let's say we want to call the increment()
function on our deployed Counter
contract without paying gas fees:
cast send 0xb3EA1C4F4f0cF65767f0c870E63523c321e92003 "increment()" \
--rpc-url anvil-zksync \
--interactive 1 \
--zk-paymaster-address 0xd9498989Fada9e78798F696B17Ab6B3b5Fe65FDF \
--zk-paymaster-input $(cast calldata "general(bytes)" "0x")
After running the command, you will be prompted to enter a private key. Select one from the list displayed when launching anvil-zksync
:
Enter private key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
What This Command Does
✅ Calls the increment()
function on the Counter
contract.
✅ Specifies anvil-zksync
as the RPC endpoint.
✅ Uses the deployed Gasless Paymaster (0xd9498989Fada9e78798F696B17Ab6B3b5Fe65FDF
) to cover the gas fees.
✅ Passes the encoded paymaster input for processing the transaction.
Once executed, the Counter contract's increment()
function should be successfully invoked without requiring the sender to pay gas fees.
Deploying a Contract with the Paymaster Using forge create
In addition to sending transactions, we can also deploy new smart contracts while using a paymaster to cover gas costs
in a single command using forge create
.
Required Flags
Similar to cast send
, the forge create
command requires:
--zk-paymaster-address
→ The address of the deployed paymaster contract.--zk-paymaster-input
→ The encoded input for the paymaster.
Deploying a Contract Using the Paymaster
To deploy a new Counter
contract without spending gas from our own wallet, run:
forge create src/Counter.sol:Counter \
--rpc-url anvil-zksync \
--interactive \
--zksync \
--zk-paymaster-address 0xd9498989Fada9e78798F696B17Ab6B3b5Fe65FDF \
--zk-paymaster-input $(cast calldata "general(bytes)" "0x")
After running the command, you will be prompted to enter a private key. Select one from the list displayed when launching anvil-zksync
:
Enter private key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
What This Command Does
✅ Deploys a new Counter
contract on ZKsync.
✅ Uses the Gasless Paymaster to cover the gas fees.
✅ Ensures the deployment is processed on a ZKsync-compatible environment (--zksync
).
Upon successful execution, the Counter contract will be deployed with gas fees covered by the paymaster.
Next Steps
🎯 Verify Balance Changes → After sending transactions and deploying contracts, check the paymaster's balance to confirm it covered the fees:
cast balance 0xd9498989Fada9e78798F696B17Ab6B3b5Fe65FDF --rpc-url anvil-zksync | cast from-wei
📖 Explore the ZKsync Paymaster Documentation → Learn more about paymaster configurations and advanced usage in the ZKsync Paymaster Docs.
🚀 Build on This → Now that you’ve successfully deployed and interacted with a Gasless Paymaster, consider extending its logic to include custom validation rules, user whitelisting, or sponsorship models for transactions!