Permit2 Approval
Last updated
import { ethers } from 'ethers';
const PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
const provider = new ethers.JsonRpcProvider(YOUR_RPC_URL);
const erc20 = new ethers.Contract(TOKEN_ADDRESS, [
'function allowance(address owner, address spender) view returns (uint256)',
'function approve(address spender, uint256 amount) returns (bool)',
], provider);
const allowance = await erc20.allowance(WALLET_ADDRESS, PERMIT2_ADDRESS);
if (allowance >= ethers.MaxUint256 / 2n) {
console.log('Already approved — no action needed.');
} else {
console.log('Approval required.');
}import { ethers } from 'ethers';
import 'dotenv/config';
const PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
// Replace with your chain's RPC URL and the token address you want to approve
const RPC_URL = process.env.RPC_BSC_MAINNET_URL; // e.g. BSC mainnet
const TOKEN_ADDRESS = '0x55d398326f99059fF775485246999027B3197955'; // USDT on BSC
const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(process.env.EVM_PRIVATE_KEY, provider);
const erc20 = new ethers.Contract(TOKEN_ADDRESS, [
'function allowance(address owner, address spender) view returns (uint256)',
'function approve(address spender, uint256 amount) returns (bool)',
], wallet);
async function approvePermit2() {
const current = await erc20.allowance(wallet.address, PERMIT2_ADDRESS);
if (current >= ethers.MaxUint256 / 2n) {
console.log('Already approved (max allowance). No action needed.');
return;
}
console.log('Approving Permit2 for MaxUint256…');
const tx = await erc20.approve(PERMIT2_ADDRESS, ethers.MaxUint256);
console.log('Tx hash:', tx.hash);
await tx.wait();
console.log('Approval confirmed.');
}
approvePermit2().catch(console.error);