Ethereum Go Client
This is a Ethereum compatible Go Client
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.
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)
result, err = contract.Call(transaction, "balanceOf", coinbase)
if result != nil && err == nil {
balance, _ := result.ToComplexIntResponse()
fmt.Println(balance.ToBigInt())
}
hash, err = contract.Send(transaction, "approve", coinbase, 10)
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)
go fmt
for all your changes.go test -v ./...
TODO List
go get -u github.com/cellcycle/go-web3
glide get github.com/cellcycle/go-web3
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
Package go-web3 is licensed under the GPLv3 License.