-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ourzora/add_batch_minting_and_further_tests
final code updates / cleanup
- Loading branch information
Showing
2 changed files
with
65 additions
and
24 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,48 @@ | ||
import 'isomorphic-fetch' | ||
|
||
const indexer_result = await fetch("https://indexer-prod-mainnet.zora.co/v1/graphql", { | ||
headers: { | ||
Accept: "*/*", | ||
"Content-Type": "application/json", | ||
}, | ||
body: '{"query":"query Token {\\n Token(where:{\\n tokenContract:{address:{_eq:\\"0xC9677Cd8e9652F1b1aaDd3429769b0Ef8D7A0425\\"}}\\n }\\n limit: 100\\n\\toffset: 0\\n) {\\n tokenId\\n owner\\n metadata {\\n json\\n }\\n }\\n}","variables":null,"operationName":"Token"}', | ||
method: "POST", | ||
}); | ||
|
||
console.log(indexer_result) | ||
import "isomorphic-fetch"; | ||
import { writeFile } from "fs/promises"; | ||
import esMain from "es-main"; | ||
|
||
async function fetchIndexer(contract, offset) { | ||
const query = `{"query":"query Token {\\n Token(where:{\\n tokenContract:{address:{_eq:\\"${contract}\\"}}\\n }\\n limit: 100\\n\\toffset: ${offset}\\n) {\\n tokenId\\n owner\\n metadata {\\n json\\n }\\n }\\n}","variables":null,"operationName":"Token"}`; | ||
console.log(query); | ||
const result = await fetch( | ||
"https://indexer-prod-mainnet.zora.co/v1/graphql", | ||
{ | ||
headers: { | ||
Accept: "*/*", | ||
"Content-Type": "application/json", | ||
}, | ||
body: query, | ||
method: "POST", | ||
} | ||
); | ||
const jsonResult = await result.json(); | ||
const tokenData = jsonResult.data.Token; | ||
return tokenData; | ||
} | ||
|
||
async function fetchLoop(contract) { | ||
let resultPart = []; | ||
let results = []; | ||
let offset = 0; | ||
do { | ||
resultPart = await fetchIndexer(contract, offset); | ||
results = results.concat(resultPart); | ||
console.log({ offset }); | ||
offset += 100; | ||
} while (resultPart.length > 0); | ||
return results; | ||
} | ||
|
||
async function fetchAllAddresses(contract) { | ||
const results = await fetchLoop(contract); | ||
console.log(`[results] has ${results.length} nfts`); | ||
writeFile("./results.json", JSON.stringify(results, null, 2)); | ||
} | ||
|
||
if (esMain(import.meta)) { | ||
const contract = process.argv[2]; | ||
console.log(`[result] fetching for contract: ${contract}`); | ||
await fetchAllAddresses(contract); | ||
console.log(`[result] done`); | ||
} |