Usage

This section explains how the Lantern.Beacon library can be integrated into a C# project.

Setting Up

To setup the library, the configuration settings for the Discv5 protocol must first be created:

// Must provide an array of Ethereum Node Records (ENRs) in string format.
// These are required for finding the relevant nodes. 
var bootstrapEnrs = new[]
{
    "enr:-Ku4QImhMc1z8yC...", 
};

// Configurable settings used by the Discovery protocol.
var tableOptions = new TableOptions(bootstrapEnrs);
var connectionOptions = new ConnectionOptions();
var sessionOptions = SessionOptions.Default;

// Create an instance of ENR (Ethereum Node Record).
// Must provide the 'v4' identity scheme and Secp256k1 public key as entries.
var enr = new EnrBuilder()
        .WithIdentityScheme(sessionOptions.Verifier, sessionOptions.Signer)
        .WithEntry(EnrEntryKey.Id, new EntryId("v4"))
        .WithEntry(EnrEntryKey.Secp256K1, new EntrySecp256K1(sessionOptions.Signer.PublicKey));

// Create a logger factory for the discovery protocol.
// Below's example sets the log level to none, however, if needed, other levels can be used.
var discv5LoggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.None));

Next, the configuration settings need to be created for the Beacon client:

Lastly, the configurations that have been setup in the previous steps must be added to ServiceCollection:

Now that all the required steps have been completed for setting up the Beacon client, the service for it can be created:

How To Use

For running the beacon client, it is first necessary to call the InitAsync method in an async manner:

This will initialize the necessary dependencies for the client to run correctly. This function must be called and awaited before starting the beacon client.

The beacon client can then be started by calling:

Last updated