ethyl

package module
v0.0.0-...-3c2eb9d Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

README

ethyl

A Golang Client Library for Communicating with Ethereum RPC Servers

Usage

Ethyl attempts to match as closely as possible the JSON-RPC API that is published on the Ethereum Wiki

Import the library:

import (
    "github.com/michaeldowling/ethyl"
)

Get a client reference:

client, clientErr := ethyl.CreateClient("http://localhost:8545");

API: Net

Get the Network Version:

version, _ := client.Net.Version();

Get the Peer Count:

peerCount, _ := client.Net.PeerCount();

Is the node listening for network connections?:

isListening, _ := client.Net.IsListening();

API: Ethereum

Get the current Ethereum Protocol Version:

version, _ := client.Eth.ProtocolVersion();

Get the list of addresses/accounts owned by client:

accounts, _ := client.Eth.Accounts();
for idx, account := range accounts {
    log.Printf("Account Address #%i:  %s \n", idx, account);
}

Get the current price per gas in wei:

gasPrice, _ := client.Eth.GasPrice();

Get the node's sync status:

isSyncing, startingBlock, currentBlock, highestBlock , err := client.Eth.Syncing();

Send a transaction onto the network:

client, clientErr := CreateClient("http://localhost:8545");
instructions := TransactionInstructions{From:client.Accounts[0], To:"0xabd5d148b31f38a8d2aa9eb041c478d36dd51c35", Gas:200000, Value:10};
txhash, err := client.Eth.SendTransaction(instructions);

Get the information about a transaction, by the Transaction Hash:

transactionObject, _ := client.Eth.GetTransactionByHash(txhash);

Get the receipt for an executed transaction, by the Transaction Hash:

transactionReceipt, _ := client.Eth.GetTransactionReceipt(txhash);

API: Contracts

Import the library:

import (
    "github.com/michaeldowling/ethyl"
    "github.com/michaeldowling/ethyl/contracts"
)

Define a contract for deployment:

contractBytecode := "6060604052604051602080610727833981016040528080519060200190919050505b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550600160016000506000600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050600001600050819055508060ff166002600050818154818355818115116100fc578183600052602060002091820191016100fb91906100d9565b808211156100f75760006000820160005060009055506001016100d9565b5090565b5b505050505b50610617806101106000396000f360606040526000357c0100000000000000000000000000000000000000000000000000000000900480635c19a95c1461005a578063609ff1bd146100725780639e7b8d6114610098578063b3f98adc146100b057610058565b005b61007060048080359060200190919050506100c8565b005b61007f60048050506103c4565b604051808260ff16815260200191505060405180910390f35b6100ae600480803590602001909190505061045b565b005b6100c6600480803590602001909190505061053d565b005b60006000600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005091508160010160009054906101000a900460ff1615610119576103bf565b5b600073ffffffffffffffffffffffffffffffffffffffff16600160005060008573ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060010160029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415801561022757503373ffffffffffffffffffffffffffffffffffffffff16600160005060008573ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060010160029054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614155b1561028857600160005060008473ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060010160029054906101000a900473ffffffffffffffffffffffffffffffffffffffff169250825061011a565b3373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614156102c1576103bf565b60018260010160006101000a81548160ff02191690830217905550828260010160026101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550600160005060008473ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005090508060010160009054906101000a900460ff16156103a257816000016000505460026000508260010160019054906101000a900460ff1660ff16815481101561000257906000526020600020900160005b506000016000828282505401925050819055506103be565b8160000160005054816000016000828282505401925050819055505b5b505050565b60006000600060009150600090505b6002600050805490508160ff161015610455578160026000508260ff16815481101561000257906000526020600020900160005b506000016000505411156104475760026000508160ff16815481101561000257906000526020600020900160005b50600001600050549150815080925082505b5b80806001019150506103d3565b5b505090565b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415806104f45750600160005060008273ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005060010160009054906101000a900460ff165b156104fe5761053a565b6001600160005060008373ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600050600001600050819055505b50565b6000600160005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005090508060010160009054906101000a900460ff168061059857506002600050805490508260ff1610155b156105a257610613565b60018160010160006101000a81548160ff02191690830217905550818160010160016101000a81548160ff02191690830217905550806000016000505460026000508360ff16815481101561000257906000526020600020900160005b506000016000828282505401925050819055505b505056";
contract := contracts.DefineContract(client, abiString, contractBytecode);

deployConfig := DeployConfig{Gas:300000};
deployResults, err := contract.Deploy(client, deployConfig);

If you want, you can actively monitor the contract's state on the blockchain:

deployChan := contract.MonitorDeploy(client, deployResults);
transactionReceipt := <-deployChan;

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LOGGER = logging.MustGetLogger("ethyl")

Functions

This section is empty.

Types

type BooleanResultEthereumNetworkResponse

type BooleanResultEthereumNetworkResponse struct {
	Id             string               `json:"id"`
	JsonRpcVersion string               `json:"jsonrpc"`
	Result         bool                 `json:"result"`
	Error          EthereumNetworkError `json:"error"`
}

type EthAPI

type EthAPI struct {
	Client *EthylClient
}

func CreateEthAPI

func CreateEthAPI(client *EthylClient) EthAPI

func (*EthAPI) Accounts

func (e *EthAPI) Accounts() ([]string, error)

func (*EthAPI) GasPrice

func (e *EthAPI) GasPrice() (int64, error)

func (*EthAPI) GetCode

func (e *EthAPI) GetCode(address string) (string, error)

func (*EthAPI) GetFilterChanges

func (e *EthAPI) GetFilterChanges(filterId string) ([]LogEntry, error)

func (*EthAPI) GetTransactionByHash

func (e *EthAPI) GetTransactionByHash(transactionHash string) (Transaction, error)

func (*EthAPI) GetTransactionMonitor

func (e *EthAPI) GetTransactionMonitor(txhash string) (chan TransactionReceipt, error)

func (*EthAPI) GetTransactionReceipt

func (e *EthAPI) GetTransactionReceipt(transactionHash string) (TransactionReceipt, error)

func (*EthAPI) NewFilter

func (e *EthAPI) NewFilter(options FilterOptions) (string, error)

func (*EthAPI) ProtocolVersion

func (e *EthAPI) ProtocolVersion() (int64, error)

func (*EthAPI) SendTransaction

func (e *EthAPI) SendTransaction(instructions TransactionInstructions, transactionArguments ...interface{}) (string, error)

func (*EthAPI) Syncing

func (e *EthAPI) Syncing() (isSyncing bool, startingBlock string, currentBlock string, highestBlock string, err error)

type EthereumFilterNetworkRequest

type EthereumFilterNetworkRequest struct {
	JsonRpcVersion string          `json:"jsonrpc"`
	Method         string          `json:"method"`
	Params         []FilterOptions `json:"params"`
	Id             string          `json:"id"`
}

type EthereumNetworkError

type EthereumNetworkError struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

type EthereumNetworkRequest

type EthereumNetworkRequest struct {
	JsonRpcVersion string        `json:"jsonrpc"`
	Method         string        `json:"method"`
	Params         []interface{} `json:"params"`
	Id             string        `json:"id"`
}

type EthylClient

type EthylClient struct {
	Url      string
	Accounts []string

	Net NetAPI
	Eth EthAPI
}

func CreateClient

func CreateClient(url string) (EthylClient, error)

func (*EthylClient) Call

func (client *EthylClient) Call(methodName string, args []string, replyValue interface{}) error

func (*EthylClient) CallWithFilterOptions

func (client *EthylClient) CallWithFilterOptions(methodName string, filterOptions FilterOptions, replyValue interface{}) error

func (*EthylClient) CallWithTransaction

func (client *EthylClient) CallWithTransaction(methodName string, instructions TransactionInstructions, args []string, replyValue interface{}) error

type FilterLogObject

type FilterLogObject struct {
	Type             string   `json:"type"`
	LogIndex         string   `json:"logIndex"`
	TransactionIndex string   `json:"transactionIndex"`
	TransactionHash  string   `json:"transactionHash"`
	BlockHash        string   `json:"blockHash"`
	BlockNumber      string   `json:"blockNumber"`
	Address          string   `json:"address"`
	Data             string   `json:"data"`
	Topics           []string `json:"topics"`
}

type FilterLogObjectResultEthereumNetworkResponse

type FilterLogObjectResultEthereumNetworkResponse struct {
	Id             string            `json:"id"`
	JsonRpcVersion string            `json:"jsonrpc"`
	Result         []FilterLogObject `json:"result"`
}

type FilterOptions

type FilterOptions struct {
	FromBlock string   `json:"fromBlock,omitempty"`
	ToBlock   string   `json:"toBlock,omitempty"`
	Address   string   `json:"address,omitempty"`
	Topics    []string `json:"topics,omitempty"`
}

type GenericSliceResultEthereumNetworkResponse

type GenericSliceResultEthereumNetworkResponse struct {
	Id             string               `json:"is"`
	JsonRpcVersion string               `json:"jsonepc"`
	Result         []interface{}        `json:"result"`
	Error          EthereumNetworkError `json:"error"`
}

type LogEntry

type LogEntry struct {
	Type             string   `json:"type"`
	LogIndex         int64    `json:"logIndex"`
	TransactionIndex int64    `json:"transactionIndex"`
	TransactionHash  string   `json:"transactionHash"`
	BlockHash        string   `json:"blockHash"`
	BlockNumber      int64    `json:"blockNumber"`
	Address          string   `json:"address"`
	Data             string   `json:"data"`
	Topics           []string `json:"topics"`
}

type NetAPI

type NetAPI struct {
	Client *EthylClient
}

func CreateNetAPI

func CreateNetAPI(client *EthylClient) NetAPI

func (*NetAPI) IsListening

func (n *NetAPI) IsListening() (bool, error)

func (*NetAPI) PeerCount

func (n *NetAPI) PeerCount() (uint64, error)

func (*NetAPI) Version

func (n *NetAPI) Version() (string, error)

type StringResultEthereumNetworkResponse

type StringResultEthereumNetworkResponse struct {
	Id             string               `json:"id"`
	JsonRpcVersion string               `json:"jsonrpc"`
	Result         string               `json:"result"`
	Error          EthereumNetworkError `json:"error"`
}

type Transaction

type Transaction struct {
	Hash             string
	Nonce            string
	BlockHash        string
	BlockNumber      int64
	TransactionIndex int64
	From             string
	To               string
	Value            string
	Gas              int64
	GasPrice         int64
	Input            string
}

type TransactionInstructions

type TransactionInstructions struct {
	From  string `json:"from"`
	To    string `json:"to,omitempty"`
	Gas   int64  `json:"gas,omitempty"`
	Data  string `json:"data,omitempty"`
	Value int64  `json:"value,omitempty"`
}

type TransactionObject

type TransactionObject struct {
	Hash             string `json:"hash"`
	Nonce            string `json:"nonce"`
	BlockHash        string `json:"blockHash"`
	BlockNumber      string `json:"blockNumber"`
	TransactionIndex string `json:"transactionIndex"`
	From             string `json:"from"`
	To               string `json:"to"`
	Value            string `json:"value"`
	Gas              string `json:"gas"`
	GasPrice         string `json:"gasPrice"`
	Input            string `json:"input"`
}

for transactions

type TransactionObjectResultEthereumNetworkResponse

type TransactionObjectResultEthereumNetworkResponse struct {
	Id             string            `json:"id"`
	JsonRpcVersion string            `json:"jsonrpc"`
	Result         TransactionObject `json:"result"`
}

type TransactionReceipt

type TransactionReceipt struct {
	TransactionHash   string `json:"transactionHash"`
	TransactionIndex  int64  `json:"transactionIndex"`
	BlockHash         string `json:"blockHash"`
	BlockNumber       int64  `json:"blockNumber"`
	CumulativeGasUsed int64  `json:"cumulativeGasUsed"`
	GasUsed           int64  `json:"gasUsed"`
	ContractAddress   string `json:"contractAddress"`
	Error             string
}

type TransactionReceiptObject

type TransactionReceiptObject struct {
	TransactionHash   string `json:"transactionHash"`
	TransactionIndex  string `json:"transactionIndex"`
	BlockHash         string `json:"blockHash"`
	BlockNumber       string `json:"blockNumber"`
	CumulativeGasUsed string `json:"cumulativeGasUsed"`
	GasUsed           string `json:"gasUsed"`
	ContractAddress   string `json:"contractAddress"`
}

type TransactionReceiptObjectResultEthereumNetworkResponse

type TransactionReceiptObjectResultEthereumNetworkResponse struct {
	Id             string                   `json:"id"`
	JsonRpcVersion string                   `json:"jsonrpc"`
	Result         TransactionReceiptObject `json:"result"`
}

Directories

Path Synopsis
crypto
sha3
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.
Package sha3 implements the SHA-3 fixed-output-length hash functions and the SHAKE variable-output-length hash functions defined by FIPS-202.

Jump to

Keyboard shortcuts

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