-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnfts.js
executable file
·67 lines (60 loc) · 2.47 KB
/
nfts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
const { ACCOUNT, COLLECTION } = require('./constants')
var argv = require('yargs/yargs')(process.argv.slice(2))
.command('Get NFTs owned by an account')
.example('$0 -a fred', 'Get NFTs owned by fred')
.example('$0 -a fred -c monsters', 'Get "monsters" collection NFTs owned by fred')
.describe('account', 'Account (account)')
.alias('a', 'account')
.default('account', ACCOUNT)
.describe('collection_name', 'Collection name')
.alias('c', 'collection_name')
.default('collection_name', COLLECTION)
.describe('template_id', 'template_id')
.alias('t', 'template_id')
.default('template_id', '')
.boolean(['debug'])
.argv
;
const { getNftsAdvanced } = require('./nft/get-nfts-advanced');
const { sortDictionary } = require('./utils');
const main = async (account, collection_name, template_id) => {
console.log(`NFTs owned by ${account}, collection ${collection_name}, template_id ${template_id}`)
const nftsAdvanced = await getNftsAdvanced({
owner: account,
collection_name: collection_name,
template_id: template_id,
sort: 'minted',
order: 'asc',
page: 1,
limit: 1000
})
if (argv.debug) console.log(nftsAdvanced)
let groupedNfts = {}
nftsAdvanced.forEach(nft => {
if (argv.debug) console.log(`${nft.template_mint}: ${nft.asset_id}`)
// if (argv.debug) console.log(nft)
if (collection_name !== '' && nft.collection.collection_name !== collection_name) {
return
}
const tpl_name = nft.template.immutable_data.name
const collection_friendly_name = nft.collection.name ? ` (${nft.collection.name})` : ''
const nft_group = `${nft.template.template_id} "${tpl_name}", ${nft.collection.collection_name}${collection_friendly_name}, `
+ `issued: ${nft.template.issued_supply}/${nft.template.max_supply}`
const nft_info = `${nft.template_mint}: ${nft.asset_id}`
if (nft_group in groupedNfts) {
groupedNfts[nft_group].push(nft_info)
} else {
groupedNfts[nft_group] = [nft_info]
}
});
const sortedNfts = sortDictionary(groupedNfts)
//if (argv.debug) console.log(sortedNfts)
Object.keys(sortedNfts).forEach(key => {
sortedNfts[key].forEach(nft => {
console.log(nft)
})
console.log(`${key}, owned: ${sortedNfts[key].length}`)
})
}
main(argv.account, argv.collection_name, argv.template_id)