【发布时间】:2021-07-29 11:34:59
【问题描述】:
while 循环创建以太坊钱包,根据生成的地址下载 robohash 头像并将其写入文件。 gLoops 设置创建的钱包数量。在继续while循环之前,我需要执行等待头像文件下载并写入文件。我认为它应该使用 async/await 来完成,但我无法理解它
let gLoops = 0;
while (gLoops < 10) {
pKey = crypto.randomBytes(32).toString("hex");
wallet = new ethers.Wallet(pKey);
address = wallet.address;
let url = urlBase + address;
https.get(url, (response) => {
let filePath = `${arg1path}\\avatars\\${address}.jpg`;
let stream = fs.createWriteStream(filePath);
response.pipe(stream);
stream.on("finish", () => {
stream.close();
console.log("Download Completed");
});
});
gLoops++;
}
【问题讨论】:
标签: javascript node.js