gas price
by jarosciak
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ethereum Gas Price</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
.container {
text-align: center;
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 24px;
margin-bottom: 10px;
}
p {
font-size: 18px;
color: #333;
}
</style>
</head>
<body>
<div class="container">
<h1>Ethereum Gas Price</h1>
<p>Enter your API key:</p>
<input type="text" id="apiKeyInput" placeholder="API key" value="">
<button id="submitBtn">Submit</button>
<div class="gas-prices">
<p>Fast Price: <span id="fastGasPrice">Loading...</span></p>
<p>Safe Price: <span id="safeGasPrice">Loading...</span></p>
<p>Proposed Price: <span id="proposeGasPrice">Loading...</span></p>
</div>
</div>
<script>
const apiKeyInput = document.getElementById('apiKeyInput');
const submitBtn = document.getElementById('submitBtn');
const fastGasPriceElement = document.getElementById('fastGasPrice');
const safeGasPriceElement = document.getElementById('safeGasPrice');
const proposeGasPriceElement = document.getElementById('proposeGasPrice');
// Load API key from local storage
const apiKey = localStorage.getItem('apiKey') || '';
// Set API key in input field
apiKeyInput.value = apiKey;
const fetchGasPrice = async () => {
try {
const response = await fetch(`https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=${apiKey}`);
const data = await response.json();
const fastGasPriceInGwei = data.result.FastGasPrice;
const safeGasPriceInGwei =...