-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_using_etherscan_api.html
81 lines (81 loc) · 2.78 KB
/
fetch_using_etherscan_api.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
href="https://aloycwl.github.io/agora_frontend/css/agora.css"
/>
<script src="https://aloycwl.github.io/js/cdn/jquery.min.js"></script>
<script src="https://aloycwl.github.io/js/cdn/web3.min.js"></script>
<script src="https://aloycwl.github.io/js/cdn/web3ac.js"></script>
<title>Agora Marketplace - World's First NFT DEX</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<b>Your NFTS</b> | <a href="index.html">Opensea API Example</a> |
<a href="buy.html">Buy Example</a><br />
<a id="body"></a>
</body>
<script>
async function load() {
if (typeof ethereum != 'undefined')
acct = await ethereum.request({ method: 'eth_requestAccounts' });
web3 = new Web3(
'https://eth-rinkeby.alchemyapi.io/v2/xneL9EV87zUlVocEVcyDT5tqp4LZE0Fy'
);
web3 = web3.eth;
a = await $.getJSON(
`https://api-rinkeby.etherscan.io/api?module=account&action=tokennfttx&address=${acct}&startblock=0&endblock=999999999&sort=desc&apikey=561643C1V7AJIMWFSBUYGWE8WG3NDVHS67`
);
for (i = 0; i < a.result.length; i++) {
r = a.result[i];
id = r.tokenID;
u = {
internalType: 'uint256',
name: 'a',
type: 'uint256',
};
if (r.to == acct[0]) {
contract = new web3.Contract(
[
{
inputs: [u1],
name: 'ownerOf',
outputs: [u3],
type: 'function',
},
{
inputs: [u1],
name: 'tokenURI',
outputs: [u5],
type: 'function',
},
],
r.contractAddress
);
contract = contract.methods;
ownerof = await contract.ownerOf(id).call();
if (ownerof.toLowerCase() == acct[0]) {
tokenuri = formatURL(await contract.tokenURI(id).call());
if (tokenuri.length > 0)
try {
b = await $.getJSON(tokenuri);
$('#body').append(
`<div class="nfts"><b>${r.tokenName} #${id}</b> - ${
b.name
}<br><i>${b.description}</i><br>${
typeof b.image != 'undefined'
? `<img src="${formatURL(b.image)}">`
: `<video autoplay muted loop><source src="${formatURL(
(img = b.animation_url)
)}"></video>`
}</div>`
);
} catch (e) {}
}
}
}
}
load();
</script>
</html>