web3

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

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

Go to latest
Published: Apr 20, 2018 License: GPL-3.0 Imports: 6 Imported by: 0

README

Go-web3 Client

Build Status

This is a Ethereum compatible Go Client which implements the Eth JSON RPC Module and NET JSON RPC Module.

Usage

Deploying a contract

bytecode := ... #contract bytecode
abi := ... #contract abi

var connection = web3.NewWeb3(providers.NewHTTPProvider("127.0.0.1:8545", 10, false))
contract, err := connection.Eth.NewContract(abi)

transaction := new(dto.TransactionParameters)
coinbase, err := connection.Eth.GetCoinbase()
transaction.From = coinbase
transaction.Gas = big.NewInt(4000000)

hash, err := contract.Deploy(transaction, bytecode, nil)

fmt.Println(hash)
	
Using contract public functions

result, err = contract.Call(transaction, "balanceOf", coinbase)
if result != nil && err == nil {
	balance, _ := result.ToComplexIntResponse()
	fmt.Println(balance.ToBigInt())
}
	
Using contract payable functions

hash, err = contract.Send(transaction, "approve", coinbase, 10)
	
Using RPC commands

GetBalance


balance, err := connection.Eth.GetBalance(coinbase, block.LATEST)

SendTransaction


transaction := new(dto.TransactionParameters)
transaction.From = coinbase
transaction.To = coinbase
transaction.Value = big.NewInt(10)
transaction.Gas = big.NewInt(40000)
transaction.Data = types.ComplexString("p2p transaction")

txID, err := connection.Eth.SendTransaction(transaction)

Installation

go get
go get -u github.com/regcostajr/go-web3
glide
glide get github.com/regcostajr/go-web3
Requirements
  • go ^1.8.3
  • golang.org/x/net

Testing

Node running in dev mode:

geth --dev --ws --wsorigins="*" --rpc --rpcapi eth,web3,personal,ssh,net --mine

Full test:

go test -v test/modulename/*.go

Individual test:

go test -v test/modulename/filename.go

License

Package go-web3 is licensed under the GPLv3 License.

Office website

– CirclePlus, @Circleplus

Documentation

Index

Constants

View Source
const (
	Coin float64 = 1000000000000000000
)

Coin - Ethereum value unity value

Variables

This section is empty.

Functions

This section is empty.

Types

type Web3

type Web3 struct {
	Provider providers.ProviderInterface
	Eth      *eth.Eth
	Net      *net.Net
	Personal *personal.Personal
	Utils    *utils.Utils
}

Web3 - The Web3 Module

func NewWeb3

func NewWeb3(provider providers.ProviderInterface) *Web3

NewWeb3 - Web3 Module constructor to set the default provider, Eth, Net and Personal

func (Web3) ClientVersion

func (web Web3) ClientVersion() (string, error)

ClientVersion - Returns the current client version. Reference: https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion Parameters:

  • none

Returns:

  • String - The current client version

Directories

Path Synopsis
complex
eth

Jump to

Keyboard shortcuts

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