ethrpc

package module
v0.0.0-...-bccdbb4 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-ethrpc

Open Source Love CircleCI Job Status Report

go-ethrpc is a Go library use for interacting to the ethereum node from your server with JSON-RPC which is a standard protocol for blockchain.

This library provides the easiest way to send JSON-RPC.

image.png

Installation

Use go get to install and update.

go get github.com/KeisukeYamashita/go-ethrpc.git

Setup

You need to setup environmental variables.

Firstly, copy the .env.sample as .env

cp .env.sample .env

Setup in your .env.

GETH_ENDPOINT: NODE_ENDPOINT

Usage and Example

This shows you that easiest request to the node which is getting the infos.

package main

import (
  "fmt"
  ethrpc "github.com/KeisukeYamashita/go-ethrpc"
  )

func main() {
	c := NewRPCClient(os.Getenv("ETHD_ENDPOINT"))
	address := "0x809826cceAb68c387726af962713b64Cb5Cb3CCA"
	balance := c.GetBalance(address)
	fmt.Print(balance) // 0.13514 ETH
}
Equal curl command
curl -X "POST" "<YOUR_GETH_NODE>" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "jsonrpc":"2.0",
  "method": "getbalance",
  "id": "1",
  "params": [
    "0x809826cceAb68c387726af962713b64Cb5Cb3CCA"
  ]
}'

It'll return a JSON.

Available Methods
method discription
eth_blockNumber gets the most recent block height.

Run tests

Set up your environmental valiables in .env to conduct this test.

cp .env.sample .env

Then write in your endpoint in this file.

Finally run your test. It will pass if your ethereum node is setted up correctly.

GO_ENV=test go test ethrpc

Contribution

To contribute, just send us a pull request! If it is valid, you will be added on the contribution doc in /doc/contributor.md .

Other Blockchain Libraries

There is a bitcoin version for this, it might help your application.

License

Copyright 2018 Yamashita Keisuke.

Licensed under the Apache 2.0 license.

Documentation

Overview

Package ethrpc implements RPC methods to interact with the ethreum node geth.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RPCClient

type RPCClient struct {
	*jsonrpc.RPCClient
}

RPCClient ...

func NewRPCClient

func NewRPCClient(endpoint string) *RPCClient

NewRPCClient ... NewRPCClient creates JSONRPC clients for your bitcoin node.

func (*RPCClient) GetBalance

func (c *RPCClient) GetBalance(addr string) (string, error)

GetBalance ... GetBalance gets the balance of eth with the given address

func (*RPCClient) GetBlockNumber

func (c *RPCClient) GetBlockNumber() (string, error)

GetBlockNumber ... GetBlockNumber gets the most resent block height

type RPCer

type RPCer interface {
	GetBlockNumber() (string, error)
}

RPCer ... Interface for other jsonrpc.

Jump to

Keyboard shortcuts

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