DrandClient

class DrandClient(api: DrandApi, cache: Cache<String, ChainInfo> = SimpleCache(), verifier: BeaconVerificationService = BeaconVerificationService()) : Closeable

Client for interacting with the drand distributed randomness network.

This client provides verified access to drand beacons with automatic cryptographic verification of all received randomness.

Example usage:

// Create client
val client = DrandClient()

// Get latest verified randomness
val beacon = client.getVerifiedLatestBeacon().getOrThrow()
println("Randomness: ${beacon.randomness}")

// Get specific round
val round1000 = client.getVerifiedBeacon(1000).getOrThrow()

// Clean up
client.close()

Or use with Kotlin's use:

DrandClient().use { client ->
val beacon = client.getVerifiedLatestBeacon().getOrThrow()
// ...
}

Parameters

api

The underlying API implementation for network transport (default: HTTP)

cache

Thread-safe cache for storing chain information to reduce network calls

verifier

Service for cryptographic verification of beacons

Constructors

Link copied to clipboard
constructor(baseUrl: String = "https://api.drand.sh", httpConfig: HttpConfig = HttpConfig(), enableCache: Boolean = true)

Creates a client using HTTP transport with the specified base URL.

constructor(api: DrandApi, cache: Cache<String, ChainInfo> = SimpleCache(), verifier: BeaconVerificationService = BeaconVerificationService())

Properties

Link copied to clipboard

Direct access to beacon operations (access by beacon ID).

Link copied to clipboard

Direct access to chain operations (access by chain hash).

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
suspend fun getChainInfo(beaconId: String): Result<ChainInfo>

Fetches chain configuration information, with automatic caching.

Link copied to clipboard
suspend fun getVerifiedBeacon(beaconId: String, round: Long): Result<RandomnessBeacon>

Fetches and verifies a specific round of randomness from a drand network.

Link copied to clipboard

Fetches and verifies the latest round of randomness from a drand network.