web3

package
v0.0.0-...-3f665cf Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/cleanunicorn/ethereum/provider"
	"github.com/cleanunicorn/ethereum/web3"
)

func main() {
	c := web3.NewClient(provider.DialHTTP("https://mainnet.infura.io"))

	// Get block number 16 without transaction data included
	b, err := c.Eth.GetBlockByNumber("0x10", false)
	if err != nil {
		fmt.Printf("Error getting latest block, err: %v", err)
	}

	// Print the block number
	fmt.Printf("Number: %#v\n", b.Number.Int64())

}
Output:

Number: 16
Example (RawCall)
package main

import (
	"encoding/json"
	"fmt"

	"github.com/cleanunicorn/ethereum/web3/eth"

	"github.com/cleanunicorn/ethereum/provider"
	"github.com/cleanunicorn/ethereum/web3"
)

func main() {
	c := web3.NewClient(provider.DialHTTP("https://mainnet.infura.io"))

	res, err := c.Provider.Call(
		// Specify the call
		"eth_getBlockByNumber",
		// Encode the parameters as expected by the node
		[]interface{}{"0x10", true},
	)
	if err != nil {
		fmt.Printf("Error getting latest block, err: %v, res: %v", err, res)
	}

	// Decode the response
	var br eth.ResponseEthGetBlockByNumber
	err = json.Unmarshal(res, &br)
	if err != nil {
		fmt.Printf("Error unmarshalling response, err: %v", err)
	}

	// Print the block number
	fmt.Printf("Number: %#v\n", br.Result.Number.Int64())

}
Output:

Number: 16

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogLevel

func SetLogLevel(level log.Level)

Types

type Client

type Client struct {
	Provider provider.Provider
	Eth      eth.Eth
	Net      net.Net
}

func NewClient

func NewClient(p provider.Provider) Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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