-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan_demo.ts
More file actions
89 lines (78 loc) · 2.07 KB
/
scan_demo.ts
File metadata and controls
89 lines (78 loc) · 2.07 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {gql, createClient, Client} from '@urql/core'
import {Address} from '@unique-nft/utils/address'
import type {CrossAccountIdOrString} from "@unique-nft/utils";
const getCollections = async (client: Client, address: CrossAccountIdOrString) => {
const collectionsQuery = gql`
query MyCollections($ownerNormalized: String) {
collections(
where: {
_or: [
{owner_normalized: {_eq: $ownerNormalized}},
{tokens: {owner_normalized: {_eq: $ownerNormalized}}},
]
},
order_by: {collection_id: asc}
offset: 0
limit: 10
) {
count
timestamp
data {
collection_id
type
token_prefix
nam
collection_cover
description
}
}
}
`;
const normalizedAddress = Address.extract.substrateOrMirrorIfEthereumNormalized(address)
const result = await client.query(
collectionsQuery,
{
$ownerNormalized: normalizedAddress
}).toPromise()
return result.data.collections
}
const getTokens = async(client: Client, address: CrossAccountIdOrString) => {
const tokensQuery = gql`
query MyTokens($ownerNormalized: String) {
tokens(
where: {
owner_normalized: {_eq: $ownerNormalized},
# collection_id: {_in: [123]}
},
order_by: {collection_id: desc, token_id: asc}
offset: 0
limit: 10
) {
count
timestamp
data {
collection_id
token_id
token_name
image
owner_normalized
date_of_creation
}
}
}
`
const normalizedAddress = Address.extract.addressForScanNormalized(address)
console.log(normalizedAddress)
const result = await client.query(
tokensQuery,
{
$ownerNormalized: normalizedAddress
}).toPromise()
return result
}
const client = createClient({
url: 'https://api-quartz.uniquescan.io/v1/graphql',
});
(async () => {
console.dir(await getTokens(client, '0x1B7AAcb25894D792601BBE4Ed34E07Ed14Fd31eB'))
})()