2019-11-08 18:55:41 +00:00
|
|
|
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 () => {
|
2020-02-04 21:29:58 +00:00
|
|
|
console.log(`Fetching assets from OpenSea`)
|
2019-11-08 18:55:41 +00:00
|
|
|
const limit = 300 // max limit
|
|
|
|
let offset = 0
|
|
|
|
const erc20Addresses = []
|
|
|
|
const nftList = []
|
|
|
|
|
|
|
|
while(true) {
|
2020-01-05 04:51:15 +00:00
|
|
|
const url = `https://api.opensea.io/api/v1/collections?limit=${limit}&offset=${offset}`
|
2020-03-31 04:37:39 +00:00
|
|
|
console.log({url})
|
2020-01-05 04:51:15 +00:00
|
|
|
const collections = await axios.get(url)
|
2019-11-08 18:55:41 +00:00
|
|
|
.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|