How to Pay Gas in ERC-20 Tokens | EIP-7702
Smart EOAs via EIP-7702
Enable users to pay gas in ERC-20 tokens using any supported ERC-20 token on Candide Paymaster.
- Create a new app on the dashboard and copy the Paymaster URL to your
.envfile - Select an ERC-20 token for gas payment and add its address to the
.envfile (this example uses CTT)
If you would like to see a full example, you can reference it here.
- index.ts
- .env
import {
...
Erc7677Paymaster,
} from "abstractionkit";
const paymasterRPC = process.env.PAYMASTER_URL as string;
const tokenAddress = process.env.TOKEN_ADDRESS as string;
const paymaster = new Erc7677Paymaster(paymasterRPC)
const { userOperation: tokenOp, tokenQuote } = await paymaster.createPaymasterUserOperation(
smartAccount, // = new Simple7702AccountV09(eoaDelegator.address)
userOperation,
bundlerUrl,
{ token: tokenAddress },
)
userOperation = tokenOp;
const cost = tokenQuote?.tokenCost;
console.log("This useroperation may cost up to : " + cost + " in the token")
console.log("Please fund the sender account: " + userOperation.sender + " with at least " + cost + " of the token")
PAYMASTER_URL=https://api.candide.dev/public/v3/11155111
TOKEN_ADDRESS=0xFa5854FBf9964330d761961F46565AB7326e5a3b # CTT address on sepolia
info
Don't forget to fund the account with ERC-20s to pay for gas. We are using Candide Test Tokens (CTT) for this example. Get test tokens from our dashboard faucet - supporting CTT and USDT on testnet.