# BSC 批量归集教程 **Published by:** [SlerfTools](https://paragraph.com/@slerftools/) **Published on:** 2025-04-05 **URL:** https://paragraph.com/@slerftools/bsc ## Content 在 BSC(Binance Smart Chain)上进行批量归集,常见于批量发放空投、钱包管理、或平台代币收集等场景。所谓“批量归集”,就是将多个地址中的 BNB 或代币统一转移到一个主地址,便于管理和后续操作。本文将介绍如何高效、安全地完成 BSC 上的批量归集操作。一、使用一键归集工具进行操作打开 BSC 批量工具: https://bsc.slerf.tools/zh-cn/token-batch-collection/bnbBSC 批量归集工具页面1、导入要批量归集的地址,填写好接受 BNB 的地址 2、选择要归集的代币,比如 BNB 或者 Token 3、填写好归集数量,然后再次确认要接受 BNB 的地址,防止归集到错误的地址丢失资产。 4、点击开始归集。二、使用代码进行归集操作准备工作1. 工具推荐Node / RPC:使用稳定的 BSC RPC 节点(如官方或自建)钱包私钥列表:包含需要归集的地址及其私钥脚本工具:Web3.jsethers.js或 Python + Web3.py主归集地址:用于接收资金的目标地址2. 安全提示私钥要加密存储,不要直接暴露在脚本中。避免用同一个 RPC 节点频繁发送交易,可使用负载均衡。使用 Testnet 模拟测试 再上线操作主网。归集 BNB(主币)BNB 作为主币,用于支付交易手续费。归集 BNB 相对简单。JavaScript 示例(ethers.js):const { ethers } = require("ethers"); const provider = new ethers.JsonRpcProvider("https://bsc-dataseed.binance.org"); const privateKeys = [/* 多个私钥 */]; const targetAddress = "0xYourTargetAddress"; async function collectBNB() { for (const pk of privateKeys) { const wallet = new ethers.Wallet(pk, provider); const balance = await provider.getBalance(wallet.address); if (balance.gt(ethers.parseEther("0.001"))) { const gasPrice = await provider.getGasPrice(); const gasLimit = 21000n; const txFee = gasPrice * gasLimit; const valueToSend = balance - txFee; const tx = await wallet.sendTransaction({ to: targetAddress, value: valueToSend, gasPrice, gasLimit }); console.log(`Sent from ${wallet.address}: ${tx.hash}`); } } } collectBNB(); 归集 BEP-20 代币归集代币稍复杂,因为需要调用 transfer() 函数,并预留 BNB 作为手续费。核心步骤:判断地址中代币余额 > 0检查是否有足够 BNB 支付手续费如果没有,可以先由主地址批量空投少量 BNB(如 0.001)执行代币转账Token 归集脚本(ethers.js):const tokenAbi = [ "function balanceOf(address) view returns (uint256)", "function transfer(address to, uint amount) returns (bool)" ]; const tokenAddress = "0xYourTokenAddress"; const tokenContract = new ethers.Contract(tokenAddress, tokenAbi, provider); async function collectToken() { for (const pk of privateKeys) { const wallet = new ethers.Wallet(pk, provider); const contractWithSigner = tokenContract.connect(wallet); const balance = await tokenContract.balanceOf(wallet.address); if (balance > 0) { const tx = await contractWithSigner.transfer(targetAddress, balance); console.log(`Token sent from ${wallet.address}: ${tx.hash}`); } } } collectToken(); 批量空投 BNB 以支付手续费(可选)当目标钱包代币余额充足但 BNB 不足时,可以从主地址统一发送 0.001~0.002 BNB:const mainWallet = new ethers.Wallet("主地址私钥", provider); const amount = ethers.parseEther("0.001"); async function airdropBNB() { for (const pk of privateKeys) { const address = new ethers.Wallet(pk).address; const tx = await mainWallet.sendTransaction({ to: address, value: amount }); console.log(`Airdropped to ${address}: ${tx.hash}`); } } 五、归集流程建议提前预估 Gas 费和 BNB 用量设置失败重试机制设置归集记录日志,防止重复归集考虑使用多线程或分批执行脚本六、常见问题(FAQ)Q1: 脚本归集速度慢怎么办?可以设置为异步批量执行,或引入队列/并发处理。Q2: 如何归集上百个地址?建议按 10~50 个为一批处理,避免 RPC 请求过多导致阻塞。Q3: 如何保证私钥安全?使用加密存储 + 环境变量 + 仅本地运行。部署到服务器需加防火墙和权限控制。七、结语BSC 上进行批量归集,是运营和钱包管理中常见的需求。通过编写脚本可以大幅提高效率,同时也要注意安全和稳定性。 ## Publication Information - [SlerfTools](https://paragraph.com/@slerftools/): Publication homepage - [All Posts](https://paragraph.com/@slerftools/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@slerftools): Subscribe to updates