Skip to content

Instantly share code, notes, and snippets.

@jimpick
Last active June 25, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimpick/43b158c212086d2467c64d81ccf854e9 to your computer and use it in GitHub Desktop.
Save jimpick/43b158c212086d2467c64d81ccf854e9 to your computer and use it in GitHub Desktop.
Lotus JS Client ChainHead Example
<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>
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