Hello guys,
i need help to make this script where it withdraw full amount of eth from wallet and dont leave a small amount on wallet , i have been search for a while but couldnt fix, thank you.
const { ethers } = require("ethers");
const provider = new ethers.providers.JsonRpcProvider("https://eth-mainnet.public.blastapi.io");
const addressReceiver = "adressre12312313";
const privateKeys =
["privatekey123123123"];
const bot = async () => {
provider.on("block", async () => {
console.log("Listening new block, waiting..)");
for (let i = 0; i < privateKeys.length; i++) {
const _target = new ethers.Wallet(privateKeys[i]);
const target = _target.connect(provider);
const balance = await provider.getBalance(target.address);
const txBuffer = ethers.utils.parseEther(".002");
if (balance.sub(txBuffer) > 0) {
console.log("NEW ACCOUNT WITH ETH!");
const amount = balance.sub(txBuffer);
try {
await target.sendTransaction({
to: addressReceiver,
value: amount
});
console.log(`Success! transfered --> ${ethers.utils.formatEther(balance)}`);
}
catch (e) {
console.log(`error: ${e}`);
}
}
}
});
}
bot();