Skip to content

moshe-blox/go-eth2-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-eth2-client

Tag License GoDoc Lint Go Report Card

Go library providing an abstraction to multiple Ethereum 2 beacon nodes. Its external API follows the official Ethereum 2 APIs specification.

This library is under development; expect APIs and data structures to change until it reaches version 1.0. In addition, clients' implementations of both their own and the standard API are themselves under development so implementation of the the full API can be incomplete.

Table of Contents

Install

go-eth2-client is a standard Go module which can be installed with:

go get github.com/attestantio/go-eth2-client

Support

go-eth2-client supports multiple beacon nodes. At current it provides support for the following:

Usage

go-eth2-client provides independent implementations for each beacon node interface, however it is generally easier to use the auto interface, as that will automatically select the correct client given the supplied address.

Please read the Go documentation for this library for interface information.

Example

Below is a complete annotated example to access a beacon node.

package main

import (
    "context"
    "fmt"
    
    eth2client "github.com/attestantio/go-eth2-client"
    "github.com/attestantio/go-eth2-client/auto"
    "github.com/rs/zerolog"
)

func main() {
    // Provide a cancellable context to the creation function.
    ctx, cancel := context.WithCancel(context.Background())
    client, err := auto.New(ctx,
        // WithAddress supplies the address of the beacon node, in host:port format.
        auto.WithAddress("localhost:4000"),
        // LogLevel supplies the level of logging to carry out.
        auto.WithLogLevel(zerolog.WarnLevel),
    )
    if err != nil {
        panic(err)
    }
    
    fmt.Printf("Connected to %s\n", client.Name())
    
    // Client functions have their own interfaces.  Not all functions are
    // supported by all clients, so checks should be made for each function when
    // casting the service to the relevant interface.
    if provider, isProvider := client.(eth2client.SlotsPerEpochProvider); isProvider {
        slotsPerEpoch, err := provider.SlotsPerEpoch(ctx)
        if err != nil {
            panic(err)
        }
        fmt.Printf("Slots per epochs is %d\n", slotsPerEpoch)
    }

    // Cancelling the context passed to New() frees up resources held by the
    // client, closes connections, clears handlers, etc.
    cancel()
}

Maintainers

Jim McDonald: @mcdee.

Contribute

Contributions welcome. Please check out the issues.

License

Apache-2.0 © 2020 Attestant Limited

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%