web3

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

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

Go to latest
Published: Jun 25, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

Ethereum Go Client

Build Status

This is a Ethereum compatible Go Client

Status

This package is currently under active development. It is not yet stable and there are some RPC methods left to implement (some to fix) and documentation to be done.

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)

Contribute!

Before a Pull Request:
  • Create at least one test for your implementation.
  • Don't change the import path to your github username.
  • run go fmt for all your changes.
  • run go test -v ./...
After a Pull Request:
  • Please use the travis log if an error occurs.
In Progress =
Partially implemented =

TODO List

  • web3_clientVersion
  • web3_sha3
  • net_version
  • net_peerCount
  • net_listening
  • eth_syncing
  • eth_coinbase
  • eth_mining
  • eth_hashrate
  • eth_gasPrice
  • eth_accounts
  • eth_blockNumber
  • eth_getBalance
  • eth_getStorageAt (deprecated)
  • eth_getTransactionCount
  • eth_getBlockTransactionCountByHash
  • eth_getBlockTransactionCountByNumber
  • eth_getUncleCountByBlockHash
  • eth_getUncleCountByBlockNumber
  • eth_getCode
  • eth_sign
  • eth_sendTransaction
  • eth_sendRawTransaction
  • eth_call
  • eth_estimateGas
  • eth_getBlockByHash
  • eth_getBlockByNumber
  • eth_getTransactionByHash
  • eth_getTransactionByBlockHashAndIndex
  • eth_getTransactionByBlockNumberAndIndex
  • eth_getTransactionReceipt
  • eth_getUncleByBlockHashAndIndex
  • eth_getUncleByBlockNumberAndIndex
  • eth_getCompilers
  • eth_compileLLL
  • eth_compileSolidity (deprecated)
  • eth_compileSerpent
  • eth_newFilter
  • eth_newBlockFilter
  • eth_newPendingTransactionFilter
  • eth_uninstallFilter
  • eth_getFilterChanges
  • eth_getFilterLogs
  • eth_getLogs
  • eth_getWork
  • eth_submitWork
  • eth_submitHashrate
  • db_putString
  • db_getString
  • db_putHex
  • db_getHex
  • shh_post
  • shh_version
  • shh_newIdentity
  • shh_hasIdentity
  • shh_newGroup
  • shh_addToGroup
  • shh_newFilter
  • shh_uninstallFilter
  • shh_getFilterChanges
  • shh_getMessages
  • personal_listAccounts
  • personal_newAccount
  • personal_sendTransaction
  • personal_unlockAccount

Installation

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

Testing

Node running in dev mode:

geth --dev --shh --ws --wsorigins="*" --rpc --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3 --mine

Full test:

go test -v ./test/...

Individual test:

go test -v test/modulename/filename.go

License

Package go-web3 is licensed under the GPLv3 License.

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
test

Jump to

Keyboard shortcuts

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