Skip to main content

drand client

A client to the drand randomness beacon network.

⚠️ This client uses esmodules and is expected to be run in the browser. If you’d like to run it in Node.js, add fetch and AbortController as globals.

⚠️ This client does not yet support verification and it should NOT be used in production for anything security critical.

Usage

The drand-client supports multiple transports, although only HTTP is available currently.

import Client, { HTTP } from 'drand-client'

const chainHash = '138a324aa6540f93d0dad002aa89454b1bec2b6e948682cde6bd4db40f4b7c9b' // (hex encoded)
const drand = await Client.wrap(
    HTTP.forURLs(['http://drand.network'], chainHash),
    { chainHash }
)
const res = await drand.get()

console.log(res)

Get a specific round

const round = 1
const res = await drand.get(round)

Get chain information

info = await drand.info()

Watch for new randomness rounds

for await (const res of drand.watch()) {
    console.log(res)
}