-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic_site.html
143 lines (135 loc) · 6 KB
/
static_site.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>web3 dApp</title>
<style>
/* Add your CSS styles here */
body {
font-family: 'Arial', sans-serif;
background-color: #121212;
color: #ffffff;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
.container {
display: flex;
justify-content: space-between;
gap: 20px;
width: 100%;
}
.box {
flex: 1;
padding: 20px;
border: 1px solid #333;
border-radius: 8px;
background-color: #1e1e1e;
}
/* ... rest of your CSS ... */
</style>
<script src="https://cdn.jsdelivr.net/npm/web3/dist/web3.min.js"></script>
</head>
<body>
<div class="container">
<div class="box">
<h1>Ethereum (ETH) Price</h1>
<p id="eth-price">Loading...</p>
</div>
<div class="box">
<h1>Download Image</h1>
<p>Click the button to download the image.</p>
<button id="download-btn" class="btn">Download Image</button>
<div id="image-container"></div>
</div>
</div>
<script>
// This will be executed once the full page is fully loaded
window.addEventListener('load', function() {
// Check if Web3 has been loaded
if (typeof Web3 !== 'undefined') {
// Use the browser's Ethereum provider
const web3 = new Web3(Web3.givenProvider || "https://rpc.ankr.com/eth_goerli");
const aggregatorV3InterfaceABI = [
{
inputs: [],
name: "decimals",
outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "description",
outputs: [{ internalType: "string", name: "", type: "string" }],
stateMutability: "view",
type: "function",
},
{
inputs: [{ internalType: "uint80", name: "_roundId", type: "uint80" }],
name: "getRoundData",
outputs: [
{ internalType: "uint80", name: "roundId", type: "uint80" },
{ internalType: "int256", name: "answer", type: "int256" },
{ internalType: "uint256", name: "startedAt", type: "uint256" },
{ internalType: "uint256", name: "updatedAt", type: "uint256" },
{ internalType: "uint80", name: "answeredInRound", type: "uint80" },
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "latestRoundData",
outputs: [
{ internalType: "uint80", name: "roundId", type: "uint80" },
{ internalType: "int256", name: "answer", type: "int256" },
{ internalType: "uint256", name: "startedAt", type: "uint256" },
{ internalType: "uint256", name: "updatedAt", type: "uint256" },
{ internalType: "uint80", name: "answeredInRound", type: "uint80" },
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "version",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
stateMutability: "view",
type: "function",
},
];
const addr = "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e";
const priceFeed = new web3.eth.Contract(aggregatorV3InterfaceABI, addr);
priceFeed.methods.latestRoundData().call().then((roundData) => {
// Now we have the roundData, we can display it
const answer = BigInt(roundData.answer);
const decimals = 1e8; // Define the decimals as a BigInt
const price = answer / BigInt(decimals); // Perform arithmetic with BigInt
const ethPriceElement = document.getElementById('eth-price');
// Convert the final result to a standard JavaScript number for display
const displayPrice = Number(price);
if (ethPriceElement) {
ethPriceElement.textContent = `The current price of Ethereum (ETH) is: $${displayPrice.toFixed(2)}`;
}
}).catch(error => {
console.error('Error fetching Ethereum price:', error);
});
} else {
console.log('Web3 is not found. Please install MetaMask!');
}
});
// Event listener for the download button
document.getElementById('download-btn').addEventListener('click', function() {
const imageUrl = 'https://link.storjshare.io/s/jvhwssk7atr2vbif3jfrvakjhcva/demo-bucket%2Fweb3%20Workshop%20Poap.png?wrap=0';
const imageContainer = document.getElementById('image-container');
imageContainer.innerHTML = `<img src="${imageUrl}" alt="Downloaded Image" style="max-width: 100%; height: auto; margin-top: 20px;">`;
});
</script>
</body>
</html>