-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solana - Moralis Vanilla JS Token Gating.html
63 lines (57 loc) · 2.1 KB
/
Solana - Moralis Vanilla JS Token Gating.html
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
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
</head>
<body>
<script>
//import you server url and app id from your moralis account
const serverUrl = "yoururl";
const appId = "yourid";
Moralis.start({ serverUrl, appId });
/* Authentication code */
async function portfolio() {
await Moralis.authenticate({ signingMessage: "This is the auth message", type: 'sol' });
const response = await Moralis.SolanaAPI.account.getPortfolio();
console.log('response', response);
getSolMetadata();
}
let getSolMetadata = async () => {
const options = {
network: "mainnet",
address: "",
};
const nftBalance = await Moralis.SolanaAPI.account.getNFTs(options);
console.log(nftBalance);
if (nftBalance.length > 0) {
console.log("looking for metadata");
maxlength = "";
if (nftBalance.length > 20) {
maxlength = 20;
} else {
maxlength = nftBalance.length;
}
for (let i = 0; i < maxlength; i++) {
let nfthash = nftBalance[i].mint;
console.log(nfthash);
try {
const options = {
network: "mainnet",
address: nfthash,
}
const metadata = await Moralis.SolanaAPI.nft.getNFTMetadata(options);
if (metadata.symbol === 'Symbol/Collection you want to gate ex DUCKS') {
document.getElementById("whatever the page wrapper for your site is called by id").style.display = "block"};
console.log(metadata.symbol);
}
catch(error) {
console.log(error)
}
}
}
}
portfolio();
</script>
</body>
</html>