JSFiddle - React, Tailwind, and code Playground
by jarosciak
HTML
<h1>Solana Validator Block Creation</h1>
<div id="blockContainer"></div>
<div id="validatorInfo">
<h2>Current Validators</h2>
<table>
<thead>
<tr>
<th>Node Pubkey</th>
<th>Stake</th>
</tr>
</thead>
<tbody id="validatorTable"></tbody>
</table>
</div>
CSS
body {
font-family: 'Arial', sans-serif;
background-color: #121212;
color: white;
text-align: center;
}
h1 {
margin-top: 20px;
}
#blockContainer {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.block {
width: 20px;
height: 20px;
background-color: #00ff00;
border-radius: 50%;
margin: 10px;
animation: grow 2s linear infinite;
}
@keyframes grow {
0% { transform: scale(0.5); }
100% { transform: scale(1.5); opacity: 0; }
}
#validatorInfo {
margin-top: 20px;
padding: 10px;
background-color: #222;
border-radius: 10px;
max-width: 500px;
margin-left: auto;
margin-right: auto;
}
table {
width: 100%;
margin-top: 10px;
}
table, th, td {
border: 1px solid #444;
border-collapse: collapse;
}
th, td {
padding: 10px;
}
JavaScript
const rpcUrl = 'https://173.214.172.170:8899';
let lastBlockHeight = 0;
// Function to create a new block animation
function createBlock() {
const block = document.createElement('div');
block.classList.add('block');
document.getElementById('blockContainer').appendChild(block);
// Remove block after animation completes
setTimeout(() => {
block.remove();
}, 2000);
}
// Function to fetch validators list
async function fetchValidators() {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "getVoteAccounts",
"params": []
}),
});
const data = await response.json();
return data.result.current;
}
// Function to fetch the latest block height
async function fetchBlockHeight() {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "getBlockHeight",
"params": []
}),
});
const data = await response.json();
return data.result;
}
// Update validators