-
Notifications
You must be signed in to change notification settings - Fork 5
/
IsOriginalMinter.js
50 lines (41 loc) · 1.39 KB
/
IsOriginalMinter.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
import { Alchemy } from "alchemy-sdk"
/**
*
* @param req contains wallet, contract, tokenId
* wallet - suspected minter
* contract - address of NFT
* tokenId - ID of NFT in question
* network - name of blockchain where contract is deployed (ex: eth-mainnet, polygon)
*
* @returns true if wallet was the original minter of tokenId from contract
* false otherwise
*/
export const IsOriginalMinter = async (req) => {
const network = req.query.network
const setNetwork = network === 'mainnet' ? "eth-mainnet" : network === 'goerli' ? "eth-goerli" : network === 'polygon' ? "polygon-mainnet" : 'invalid'
let settings = {
apiKey: process.env.ALCHEMY_KEY,
network: setNetwork
}
const alchemy = new Alchemy(settings)
if(settings.network === 'invalid'){
throw 'Network was not specified'
}
const wallet = req.query.wallet
const contract = req.query.contract
const id = req.query.tokenId
const res = await alchemy.core.getAssetTransfers({
fromBlock: "0x0",
fromAddress: "0x0000000000000000000000000000000000000000",
toAddress: wallet,
excludeZeroValue: true,
contractAddresses: [contract],
category: ["erc721", "erc1155"],
});
for(let i = 0; i < res.transfers.length; i++) {
if(parseInt(res.transfers[i].tokenId) === parseInt(id)) {
return true
}
}
return false
}