Created
September 28, 2022 14:46
-
-
Save coindegen/0f15268a4e248a14bb9f5e5df5a3a045 to your computer and use it in GitHub Desktop.
replace address with checksum version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ethers } from "ethers" | |
import { MongoClient } from "mongodb" | |
require("dotenv-safe").config() | |
const DATABASE_URI = process.env.DATABASE_URI || "" | |
const DATABASE_NAME = process.env.DATABASE_NAME | |
async function main() { | |
try { | |
let client = new MongoClient(DATABASE_URI) | |
await client.connect() | |
let db = client.db(DATABASE_NAME) | |
const collection = db.collection("Users") | |
const res = await collection | |
.find({}, { sort: { joined_time: 1 }, skip: 3100 }) | |
.limit(1000) | |
.toArray() | |
console.log({ res }) | |
let i = 0 | |
for (const affiliate of res) { | |
const filter = { _id: affiliate._id } | |
const updateDocument = { | |
$set: { | |
address: ethers.utils.getAddress(affiliate.address), | |
}, | |
} | |
const result = await collection.updateOne(filter, updateDocument) | |
if (result.modifiedCount > 0) { | |
i++ | |
console.log(i) | |
} | |
} | |
console.log("\nDone") | |
console.log(`Total docs modified: ${i}\n`) | |
process.exit(0) | |
} catch (e) { | |
console.log(e) | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment