Skip to content

Commit

Permalink
Fixes readme exemple
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin committed Nov 9, 2024
1 parent 32050dc commit 40d7bda
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Options:
<html>
<head>
<title>Monitoring</title>
<script src="https://unpkg.com/[email protected].0/dist/index.esm.js" charset="UTF-8" integrity="sha384-X8BhAzHFjiYdkiKncK7nKxHWpRTmp/FSQm0tm3ipI2f2wm6L32G1N/cKmu7xqkNm" crossorigin="anonymous"></script>
<link rel="modulepreload" href="https://unpkg.com/[email protected].1/dist/index.esm.js" charset="UTF-8" integrity="sha384-Rp+AJiqSkCwPajGgNf1TGdWRVDSgf5GtK1pgO7uPofbSxPVNaZ/wNdulNxKVaO6I" crossorigin="anonymous"></script>
<style>
body {
padding: 2rem;
Expand All @@ -68,7 +68,8 @@ Options:
<div id="main-alphanet"></div>
<div id="main-moonriver"></div>
<div id="main-moonbeam"></div>
<script>
<script type="module">
import * as mbTools from "https://unpkg.com/[email protected]/dist/index.esm.js";
const monitorNetwork = async (api, networkName) => {
const pre = document.createElement("pre");
const title = document.createElement("h2");
Expand Down
61 changes: 61 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>

<head>
<title>Monitoring</title>
<link rel="modulepreload" href="./dist/index.esm.js" charset="UTF-8"
integrity="sha384-Rp+AJiqSkCwPajGgNf1TGdWRVDSgf5GtK1pgO7uPofbSxPVNaZ/wNdulNxKVaO6I" crossorigin="anonymous">
<style>
body {
padding: 2rem;
}

pre {
margin: 0;
}
</style>
</head>

<body>
<div id="main-alphanet"></div>
<div id="main-moonriver"></div>
<div id="main-moonbeam"></div>
<script type="module">
import * as mbTools from "./dist/index.esm.js";
const monitorNetwork = async (api, networkName) => {
const pre = document.createElement("pre");
const title = document.createElement("h2");
title.append(networkName);
const main = document.getElementById(`main-${networkName}`);
main.appendChild(title);
main.appendChild(pre);
let previousBlockDetails = null;
mbTools.listenBlocks(api, false, async (blockDetails) => {
const line = `${mbTools.generateBlockDetailsLog(
blockDetails,
{},
previousBlockDetails
)}\n`;
pre.prepend(line);
previousBlockDetails = blockDetails;
});
return api;
};

const start = async () => {
const api = await mbTools.getApiFor({ network: "moonriver" });
// You can also directly to the node using url
// const api = await mbTools.getApiFor({ url: "ws://127.0.0.1:9944" });

const networkName =
mbTools.NETWORK_CHAIN_MAPPING[
(await api.rpc.system.chain()).toString()
];
monitorNetwork(api, networkName);
};

start();
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moonbeam-tools",
"version": "0.1.0",
"version": "0.1.1",
"description": "Set of tools for Moonbeam blockchain",
"exports": {
".": {
Expand Down

0 comments on commit 40d7bda

Please sign in to comment.