ethereum

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

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

Go to latest
Published: Aug 20, 2018 License: Apache-2.0 Imports: 7 Imported by: 2

README

Warning: gopherjs-eth is not production ready and should not be deemed secure.

gopherjs-eth

gopherjs-eth is an experimental GopherJS wrapper on web3.js (v0.20.X). It is not fully compatible with Metamask.

gopherjs-eth is not actively maintained.

Getting Started

Examples
import (
	...
	ethereum "github.com/gbotrel/gopherjs-eth"
)


eth, err := ethereum.Init("http://localhost:8545")

eth.IsConnected()
eth.IsMetamask()
eth.ActiveAccount()
eth.DeployContract(myABI, opts)

Sample project

This ZSL Demonstrator uses gopherjs-eth package.

License

This project is licensed under the Apache 2 License - see the LICENSE file for details

Documentation

Overview

Package ethereum is a experimental GopherJS wrapper around web3js (v 0.20.x)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallOpts

type CallOpts struct {
	Gas  *big.Int
	Wei  *big.Int
	From string
	Data string
}

CallOpts is an helper to perform transactions

func (*CallOpts) ToJSObject

func (opts *CallOpts) ToJSObject() *js.Object

ToJSObject converts CallOpts to a JSObject (json like)

type Contract

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

Contract represents a smart contract wrapper

func (*Contract) Call

func (c *Contract) Call(method string, opts CallOpts, args ...interface{}) (*js.Object, error)

Call calls method and wait (block) until response

func (*Contract) SubscribeToEvent

func (c *Contract) SubscribeToEvent(eventName string, chEvents chan *Event)

SubscribeToEvent will fetch all events from block 0 and watch new ones events are sent to channel chEvents

type Ethereum

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

Ethereum represents a connection to the blockchain through web3.js

func Init

func Init(nodeURL string) (*Ethereum, error)

Init initializes web3.js with a http provider

func InitMetamask

func InitMetamask() (*Ethereum, error)

InitMetamask ensure the web3 object is initialized with Metamask provider Note: some contract functions are not functional with Metamask

func (*Ethereum) ActiveAccount

func (eth *Ethereum) ActiveAccount() (string, error)

ActiveAccount returns web3.eth.accounts[0]

func (*Ethereum) Balance

func (eth *Ethereum) Balance(account string) (*big.Int, error)

Balance return the balance (in Eth) of the given account

func (*Ethereum) Contract

func (eth *Ethereum) Contract(abi, address string) *Contract

Contract binds an abi and an address to a contract object

func (*Ethereum) DeployContract

func (eth *Ethereum) DeployContract(abi string, opts CallOpts, args ...interface{}) (string, *Contract, error)

DeployContract deploys a new contract and waits for it to be mined returns its address , the contract object or an error

func (*Ethereum) FromWei

func (eth *Ethereum) FromWei(wei *big.Int) *big.Int

FromWei converts wei to ether

func (*Ethereum) IsConnected

func (eth *Ethereum) IsConnected() bool

IsConnected return connection status

func (*Ethereum) IsMetamask

func (eth *Ethereum) IsMetamask() bool

IsMetamask returns true if current provider of web3.js object === metamask

func (*Ethereum) NetworkID

func (eth *Ethereum) NetworkID() (int, error)

NetworkID returns the networkID web3 object is connected to

func (*Ethereum) ToWei

func (eth *Ethereum) ToWei(ether *big.Int) *big.Int

ToWei converts ether to wei

type Event

type Event struct {
	Address         string
	Event           string
	TransactionHash string
	BlockHash       string
	BlockNumber     int
	LogIndex        int
	Args            map[string]interface{}
}

Event represents an event emitted by the blockchain

func (*Event) UID

func (e *Event) UID() string

UID returns an unique ID for the Event

Jump to

Keyboard shortcuts

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