web3

package module
Version: v0.0.0-...-8e02f3b Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: Apache-2.0 Imports: 2 Imported by: 0

README

go-web3

GoDoc Go Report Card

A wrapper for web3 to be used with GopherJS. Tries to enforce best practices. Methods are called asynchronously to maintain support for metamask and mist.

Documentation

GoDoc

Getting Started

$ go get -u github.com/jaynagpaul/go-web3 $ go get -u github.com/gopherjs/gopherjs


import "github.com/jaynagpaul/go-web3"

func main() {
    // Check if injected by browser
    w3 := web3.NewWeb3()
    w3.Version.GetEthereum(func(ver, err) {
        if err != nil {
            println(err)
        } else {
            println(ver) // Prints the version to the developer console.
        }
    })
    // TODO
}

gopherjs build

More Examples

One More

TODO

  • Framework for testing.
  • Finalize API.
  • Examples

Documentation

Overview

Package web3 provides a wrapper for ethereum's web3.js for use with gopherjs.

Getting Started:

$ go get -u github.com/jaynagpaul/go-web3

$ go get -u github.com/gopherjs/gopherjs

import "github.com/jaynagpaul/go-web3"

func main() {
	// Check if injected by browser
	w3 := web3.NewWeb3()
	w3.Version.GetEthereum(func(ver, err) {
		if err != nil {
			println(err)
		} else {
			println(ver) // Prints the version to the developer console.
		}
	})
	// TODO
}

$ gopherjs build

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Version

type Version struct {
	API string // The ethereum JS api version.
	// contains filtered or unexported fields
}

Version of the various protocols and apis

func (*Version) GetEthereum

func (v *Version) GetEthereum(callback func(string, error))

GetEthereum takes a callback with ethereum version and error as a params Returns the ethereum protocol version.

func (*Version) GetNetwork

func (v *Version) GetNetwork(callback func(string, error))

GetNetwork takes a callback with network version and error as a params Returns the network protocol version.

func (*Version) GetNode

func (v *Version) GetNode(callback func(string, error))

GetNode takes a callback with node version and error as a params Returns the client/node version.

func (*Version) GetWhisper

func (v *Version) GetWhisper(callback func(string, error))

GetWhisper takes a callback with whisper version and error as a params Returns the whisper protocol version.

type Web3

type Web3 struct {
	Version Version
	// contains filtered or unexported fields
}

Web3 instance

func NewWeb3

func NewWeb3(args ...interface{}) *Web3

NewWeb3 creates a Web3 instance with args passed to Web3.providers.HttpProvider. HttpProvider takes 4 arguments (host, timeout, user, password)

func (*Web3) CurrentProvider

func (w3 *Web3) CurrentProvider() bool

CurrentProvider can be used to check if mist, metamask etc. have already set a provider.

func (*Web3) IsConnected

func (w3 *Web3) IsConnected() bool

IsConnected should be called to check if a connection to a node exists

func (*Web3) Reset

func (w3 *Web3) Reset(keepIsSyncing bool)

Reset can be called to reset state of web3. Resets everything except manager. Uninstalls all filters. Stops polling. If keepIsSyncing is true it will uninstall all filters, but will keep the web3.eth.isSyncing() polls

func (*Web3) SetProvider

func (w3 *Web3) SetProvider(args ...interface{})

SetProvider should be called to set provider. See NewWeb3 for more detailed information on args.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL