Blacklisting users

Prevent certain wallets from receiving gas free transactions.


1

Enabling the blacklist

We can also turn on blacklist mode, where users on the blacklist will be unable to use the paymaster to send gasless transactions.

// Enable the blacklist - note, you can only use either the whitelist or the blacklist
const setBlacklistModeTx = await gaslessSponsor.setToBlacklistMode()
await auth.sendTxs([setBlacklistModeTx])
2

Adding a user to the blacklist

We can add a user to the blacklist using the code below

const addSpenderToBlacklistTx = await gaslessSponsor.addSpenderToBlackList(await wallet.getAddress())
await auth.sendTxs([addSpenderToBlacklistTx])
3

Removing a user from the blacklist

Or remove a user from the blacklist using the code below

const removeSpenderFromBlacklistTx = await gaslessSponsor.removeSpenderFromBlackList(await wallet.getAddress())
await auth.sendTxs([removeSpenderFromBlacklistTx])

Full code

Here is the full runnable code block for blacklisting users:

,
sponsorGas.js
const { FunWallet/configureEnvironment } = require("fun-wallet")
const { Eoa } = require("fun-wallet/auth")
const { fundWallet } = require("fun-wallet/utils")
const { GaslessSponsor } = require("fun-wallet/sponsors/GaslessSponsor")
const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"
const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"
const auth = new Eoa({privateKey: PRIVATE_KEY})
const options = {
apiKey: API_KEY,
}
await configureEnvironment(options)
uid = await auth.getUniqueId()
wallet = new FunWallet({ uid, index: Math.ceil(Math.random() * 100_000_000) })
const authAddress = await auth.getUniqueId()
await configureEnvironment({
gasSponsor: {
sponsorAddress: await auth.getUniqueId(),
}
})
await fundWallet(auth, wallet, .005)
const gaslessSponsor = new GaslessSponsor()
const stakeAmount = ".01"
const stake = await gaslessSponsor.stake(authAddress, stakeAmount)
await auth.sendTxs([stake])
const setWhitelistModeTx = await gaslessSponsor.setToWhitelistMode()
const addSpenderToWhitelistTx = await gaslessSponsor.addSpenderToWhiteList(await wallet.getAddress())
const removeSpenderFromWhitelistTx = await gaslessSponsor.removeSpenderFromWhiteList(await wallet.getAddress())
await auth.sendTxs([setWhitelistModeTx, addSpenderToWhitelistTx, removeSpenderFromWhitelistTx])
// Modifying Blacklist - note, you can only use either the whitelist or the blacklist
const setBlacklistModeTx = await gaslessSponsor.setToBlacklistMode()
const addSpenderToBlacklistTx = await gaslessSponsor.addSpenderToBlackList(await wallet.getAddress())
const removeSpenderFromBlacklistTx = await gaslessSponsor.removeSpenderFromBlackList(await wallet.getAddress())
await auth.sendTxs([setBlacklistModeTx, addSpenderToBlacklistTx, removeSpenderFromBlacklistTx])