forked from trustwallet/assets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopesea_contrats.ts
34 lines (30 loc) · 1.04 KB
/
opesea_contrats.ts
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
var axios = require("axios");
import { toChecksum } from "../src/test/helpers"
// Returns array of ERC-721, ERC-1155 contract addresses in checksum
export const getOpenseaCollectionAddresses = async () => {
const limit = 300 // max limit
let offset = 0
const erc20Addresses = []
const nftList = []
while(true) {
const url = `https://api.opensea.io/api/v1/collections?limit=${limit}&offset=${offset}`
const collections = await axios.get(url)
.then(res => res.data.collections)
.catch(e => console.log(e.message))
collections.forEach(c => {
c.primary_asset_contracts.forEach(a => {
const checksum = toChecksum(a.address)
if (a.schema_name === "ERC20") {
erc20Addresses.push(checksum)
} else {
nftList.push(checksum)
}
})
})
if(collections.length < limit) {
return nftList
} else {
offset += limit
}
}
}