This is a Ethereum compatible Go Client which implements the Eth JSON RPC Module and NET JSON RPC Module.
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 get -u github.com/regcostajr/go-web3
glide get github.com/regcostajr/go-web3
- go ^1.8.3
- golang.org/x/net
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
Package go-web3 is licensed under the GPLv3 License.
– CirclePlus, @Circleplus