Skip to content

Instantly share code, notes, and snippets.

@skyMetaverse
Created June 18, 2024 08:46
Show Gist options
  • Select an option

  • Save skyMetaverse/cefa88826845bd53c4987383248960cd to your computer and use it in GitHub Desktop.

Select an option

Save skyMetaverse/cefa88826845bd53c4987383248960cd to your computer and use it in GitHub Desktop.
zksync-lite 归集ETH脚本
const ethers = require('ethers');
const zksync = require('zksync');
const readLines = require('readfile-syskey');
// 归集的钱包地址
const COLLECT_RECEIPTADDRESS = "改成自己的归集的钱包地址";
if (COLLECT_RECEIPTADDRESS === "") {
console.log("请填写归集的钱包地址");
process.exit();
};
let sendEth = async (pk) => {
let ethersProvider = ethers.getDefaultProvider('mainnet');
let ethWallet = new ethers.Wallet(pk, ethersProvider);
let address = ethWallet.address;
try {
let syncHttpProvider = await zksync.getDefaultProvider('mainnet');
let syncWallet = await zksync.Wallet.fromEthSigner(ethWallet, syncHttpProvider);
let committedETHBalance = await syncWallet.getBalance('ETH');
console.log(`${address} - ETH余额: ${ethers.utils.formatEther(`${committedETHBalance}`, 18)}`);
let fee = ethers.utils.parseEther("0.00001195"); // 0.00000772 0.00001195
if (committedETHBalance.gt(fee)) {
let amount = committedETHBalance.sub(fee);
amount = zksync.utils.closestPackableTransactionAmount(amount);
let transfer = await syncWallet.syncTransfer({
to: COLLECT_RECEIPTADDRESS,
token: 'ETH',
amount: amount,
});
let transferReceipt = await transfer.awaitReceipt();
if (transferReceipt.success === true) {
console.log(`${ethWallet.address} - 发送ETH成功 接收钱包地址: ${COLLECT_RECEIPTADDRESS}`);
} else {
console.log(`${ethWallet.address} - 发送ETH失败`);
};
} else {
console.log(`${address} - 余额小于转账需要的fee`);
};
} catch (err) {
console.log(`${ethWallet.address} - 发送ETH出错: ${err}`);
};
};
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
let main = async () => {
let pks = await readLines('./pks.txt');
let start = 0;
let batchSize = 2;
while (start < pks.length) {
let batch = pks.slice(start, start + batchSize);
let results = batch.map(async (pk) => {
await sendEth(pk);
});
await Promise.all(results);
start += batchSize;
};
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment