gethaws

package module
v0.9.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 9 Imported by: 1

README

Geth Client For AWS Managed Blockchain

Generates RPC clients for regular JSON-RPC clients such as Infura or Alchemy, and for Managed Blockchain which uses a custom authentication mechanism.

Installing

go get github.com/said1296/gethaws

Limitations

Only works for HTTP client, will add support for other client types if people request it.

Usage

In this example the clients are configured loading the configuration from env variables. Further config instructions found at:

https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/

You can also pass an aws.Config struct instead of nil to CreateClients in order to use a custom aws.Config.

package main

import (
    "context"
    "github.com/aws/aws-sdk-go-v2/config"
    "net/http"
    "os"
)

func main() {
    err := os.Setenv("AWS_REGION", "us-east-2")
    if err != nil {
        panic(err)
    }
    err = os.Setenv("AWS_ACCESS_KEY_ID", "my_access_key_id")
    if err != nil {
        panic(err)
    }
    err = os.Setenv("AWS_SECRET_ACCESS_KEY", "my_secret_access_key")
    if err != nil {
        panic(err)
    }
    
    // The most common use cases will only use the first returned client, the rpc client is for low level calls not 
    // implemented by geth.
    // The clients can also be created with a manually created aws.Config by passing it instead of nil.
    client, rpcClient, err := gethaws.CreateClients(ctx.Background(), "https://ethereum.managedblockchain/1jsj1i23213nk32mo1", nil)
    if err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAwsClients added in v0.9.17

func CreateAwsClients(ctx context.Context, endpoint string) (*ethclient.Client, *rpc.Client, error)

CreateAwsClients creates an ethclient.Client and an rpc.Client from from a context and an endpoint, AWS config is fetched from config.LoadDefaultConfig of aws package which uses environment variables to get credentials. Refer to: https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html

func CreateAwsClientsFromConfig added in v0.9.17

func CreateAwsClientsFromConfig(endpoint string, config aws.Config) (*ethclient.Client, *rpc.Client, error)

CreateAwsClientsFromConfig creates an ethclient.Client and an rpc.Client from an endpoint string and an aws.Config struct

func CreateClients

func CreateClients(ctx context.Context, rpcUrl string, config *aws.Config) (client *ethclient.Client, rpcClient *rpc.Client, err error)

CreateClients determines the Provider type from the rpcUrl passed. If config is different than nil and the provider type is ProviderAws, then CreateAwsClientsFromConfig is used to generate the clients, otherwise CreateAwsClients is used.

Types

type CreationError

type CreationError struct {
	// contains filtered or unexported fields
}

func (CreationError) Error

func (e CreationError) Error() string

type Provider added in v0.9.17

type Provider string
const (
	ProviderAws     Provider = "aws"
	ProviderRegular Provider = "regular"
)

func GetEvmProviderType added in v0.9.17

func GetEvmProviderType(rpcUrl string) Provider

GetEvmProviderType determines if the provider url is for an AWS or regular JSON-RPC

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL