Skip to content

Instantly share code, notes, and snippets.

@Lytes
Last active July 13, 2024 13:01
Show Gist options
  • Save Lytes/4ff1f5d44bec5c6d9bb8b7d0b98765bf to your computer and use it in GitHub Desktop.
Save Lytes/4ff1f5d44bec5c6d9bb8b7d0b98765bf to your computer and use it in GitHub Desktop.
// An example that removes spending permissions of hacker controlled addresses on erc20 tokens using the paymaster
//
import { Provider, types, Wallet, utils } from "zksync-ethers";
import { ethers } from "ethers";
const PRIVATE_KEY = "0000000000000000000000000000000000000000000000000000000000000000"
const paymasterAddress = "0x0000000000000000000000000000000000000000"; // Paymaster
const walletAddresses = [
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
]
const rpcUrl = "<YOUR_RPC_URL>"
const token = new ethers.Interface(require("./Token.json").abi) // erc 20 interface, can use abi
//const provider = Provider.getDefaultProvider(types.Network.Sepolia); // Sepolia test
const provider = new Provider(rpcUrl);
const ethProvider = ethers.getDefaultProvider("mainnet");
const wallet = new Wallet(PRIVATE_KEY, provider, ethProvider);
const tokenAddress = "0x0000000000000000000000000000000000000000" // ERC20 Token to remove spending allowance from
async function removeSpending() {
for (const address of walletAddresses){
try {
const setAllowance = await wallet.sendTransaction({
type: utils.EIP712_TX_TYPE, // Tx type required to use paymaster
to: tokenAddress,
data: token.encodeFunctionData("approve", [address, 0]),
customData: {
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
paymasterParams: utils.getPaymasterParams(paymasterAddress, {
type: "General",
innerInput: new Uint8Array(),
}),
}
})
const receipt = await setAllowance.wait()
console.log(`${receipt} : ${address} kicked out`)
} catch (err){
console.log("error ", err)
}
}
}
async function main() {
await removeSpending();
}
main()
.then()
.catch((error) => {
console.log(`Error: ${error}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment