Last active
June 25, 2020 15:05
-
-
Save jimpick/43b158c212086d2467c64d81ccf854e9 to your computer and use it in GitHub Desktop.
Lotus JS Client ChainHead Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Lotus: Chain Head</title> | |
</head> | |
<body> | |
<h3>ChainHead</h3> | |
Height: <span id='height'></span> | |
<script type="module" src="./script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LotusRPC } from 'https://unpkg.com/@filecoin-shipyard/lotus-client-rpc?module' | |
import { BrowserProvider } from 'https://unpkg.com/@filecoin-shipyard/lotus-client-provider-browser?module' | |
import { testnet } from 'https://unpkg.com/@filecoin-shipyard/lotus-client-schema?module' | |
const wsUrl = 'wss://lotus.testground.ipfs.team/api/0/node/rpc/v0' | |
const provider = new BrowserProvider(wsUrl) | |
const client = new LotusRPC(provider, { schema: testnet.fullNode }) | |
setInterval(async () => { | |
const result = await client.chainHead() | |
document.querySelector('#height').textContent = result.Height | |
}, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment