This script monitors a BSC wallet for incoming BNB and automatically transfers a specified ERC20 token upon detection.
- 🔍 Real-time monitoring of BNB balance
- ⚡ Fast reaction to incoming BNB
- 💸 Automatic ERC20 token transfer
- ⚙️ Configurable gas price and token amount
- Node.js (v14 or later)
- npm (Node Package Manager)
- A BSC wallet with:
- BNB for gas fees
- The ERC20 token you want to transfer
-
Clone this repository:
git clone https://github.com/yourusername/bnb-to-erc20-transfer-script.git cd bnb-to-erc20-transfer-script -
Install dependencies:
npm install -
Create a
.envfile in the project root:PRIVATE_KEY=your_wallet_private_key_here
Edit the following variables in script.js:
tokenAddress: The contract address of your ERC20 tokenrecipientAddress: The address to receive the ERC20 tokenscheckInterval: How often to check for new BNB (in milliseconds)
Run the script:
node script.js
The script will start monitoring your wallet for incoming BNB. When BNB is detected, it will automatically transfer the maximum available balance of the specified ERC20 token to the recipient address.
- 🔒 Keep your private key secure! Never share your
.envfile. - 💰 Ensure your wallet has enough BNB for gas fees.
- 🏎️ The script is optimized for speed and may not wait for transaction confirmations.
- 📡 Frequent balance checks may put a high load on your node provider.
To change the gas price, modify the prepareTransferTx function:
tx.gasPrice = ethers.parseUnits('15', 'gwei'); // Adjust as neededTo transfer a specific amount instead of the maximum, modify the main function:
const transferAmount = ethers.parseUnits('100', 18); // Adjust amount and decimals
await transferERC20(transferAmount);This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
Your Name
- GitHub: @lem0ntree
⭐️ If you find this project useful, please give it a star on GitHub! ⭐️