ERC20 Paymaster
This guide will help you get started with the Zyfi API to transform a normal transaction in a paymaster one.
For advanced usage and detailed explanation of each parameter and feature, please explore our detailed API documentation.
The basic flow consists of the following steps:
Collect the desired transaction payload and the ERC20 the user desires to pay with
Send an API request
Receive back the quote and transaction payload for the user to sign
Step 1: Send the API request
Send the required data to the erc20_paymaster
endpoint. Below an example implementation using Javascript fetch (natively supported in most environments)
The returned object does not change the original transaction calldata, but add the paymaster fields necessary to process the transaction.
Step 2: Show the quote to the user
The response, on top of the transaction payload, returns a series of helper values that can be used by the UI to better inform the user. In particular:
tokenAddress
: ERC20 token address used to pay for the gas fee (feeToken)tokenPrice
: the estimated cost of the feeTokenfeeTokenAmount
: Max amount of the ERC20 token that the user will pay as fee (before refunds). The user need to have this balance for the transaction to not failfeeUSD
: Equivalent value of feeTokenAmount in USDmarkup
: Markup or discount applied on the gas feeexpirationTime
:block.timestamp
of the quote expiration. Currently it's one hour
Transactions on zkSync overestimate the gas needed and receive a refund at the end, which is difficult to know in advance.
The unspent gas is refunded to the user in the feeToken.
We suggest to to each protocol to implement their own estimation for the final cost by observing the actual gas being used on their transaction.
We also provide a very rough estimation with estimatedFinalFeeTokenAmount
and estimatedFinalFeeUSD
Step 3: Execute the transaction
Last updated