diff --git a/README.md b/README.md index ac2eb493..138bc9c9 100644 --- a/README.md +++ b/README.md @@ -98,3 +98,25 @@ err := client.Call( eth.CallFunc(funcBalanceOf, dai, addr).Returns(&daiBalance), ) ``` + + +## RPC Methods + +List of supported RPC methods: + +Method | Go Code +-----------------------------|--------- +`eth_blockNumber` | `eth.BlockNumber().Returns(blockNumber *big.Int)` +`eth_call` | `eth.Call(msg ethereum.CallMsg).Returns(output *[]byte)`
`eth.CallFunc(fn core.Func, to common.Address, args ...interface{}).Returns(returns ...interface{})` +`eth_chainId` | `eth.ChainID().Returns(chainID *uint64)` +`eth_gasPrice` | `eth.GasPrice().Returns(gasPrice *big.Int)` +`eth_getBalance` | `eth.Balance(addr common.Address).Returns(balance *big.Int)` +`eth_getBlockByHash` | `eth.BlockByHash(hash common.Hash).Returns(block *types.Block)`
`eth.HeaderByHash(hash common.Hash).Returns(header *types.Header)` +`eth_getBlockByNumber` | `eth.BlockByNumber(number *big.Int).Returns(block *types.Block)`
`eth.HeaderByNumber(number *big.Int).Returns(header *types.Header)` +`eth_getCode` | `eth.Code(addr common.Address).Returns(code *[]byte)` +`eth_getLogs` | `eth.Logs(q ethereum.FilterQuery).Returns(logs *[]types.Log)` +`eth_getStorageAt` | `eth.StorageAt(addr common.Address, slot common.Hash).Returns(storage *common.Hash)` +`eth_getTransactionByHash` | `eth.TransactionByHash(hash common.Hash).Returns(tx *types.Transaction)` +`eth_getTransactionCount` | `eth.Nonce(addr common.Address).Returns(nonce *uint64)` +`eth_getTransactionReceipt` | `eth.TransactionReceipt(hash common.Hash).Returns(receipt *types.Receipt)` +`eth_sendRawTransaction` | `eth.SendTransaction(tx *types.Transaction).Returns(hash *common.Hash)`
`eth.SendRawTransaction(rawTx []byte).Returns(hash *common.Hash)` diff --git a/example_test.go b/example_test.go index aefe12a0..8c2937d0 100644 --- a/example_test.go +++ b/example_test.go @@ -2,7 +2,6 @@ package w3_test import ( "fmt" - "log" "math/big" "github.com/ethereum/go-ethereum/common" @@ -14,11 +13,17 @@ import ( func ExampleDial() { client, err := w3.Dial("https://cloudflare-eth.com") if err != nil { - log.Fatalf("Failed to connect to RPC endpoint: %v", err) + fmt.Printf("Failed to connect to RPC endpoint: %v\n", err) + return } defer client.Close() } +func ExampleMustDial() { + client := w3.MustDial("https://cloudflare-eth.com") + defer client.Close() +} + func ExampleI() { fmt.Printf("%v wei\n", w3.I("0x2b98d99b09e3c000")) fmt.Printf("%v wei\n", w3.I("3141500000000000000")) @@ -80,7 +85,7 @@ func ExampleClient_Call() { addr = w3.A("0x000000000000000000000000000000000000dEaD") weth9 = w3.A("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2") - // Declare a Smart Contract function with Solidity syntax, + // Declare a Smart Contract function using Solidity syntax, // no "abigen" and ABI JSON file needed. balanceOf = w3.MustNewFunc("balanceOf(address)", "uint256") @@ -95,7 +100,7 @@ func ExampleClient_Call() { eth.Balance(addr).Returns(ðBalance), eth.CallFunc(balanceOf, weth9, addr).Returns(&weth9Balance), ); err != nil { - fmt.Printf("Requst failed: %v\n", err) + fmt.Printf("Request failed: %v\n", err) return } diff --git a/module/eth/get_block_by_hash.go b/module/eth/get_block_by_hash.go index 77920627..823f92aa 100644 --- a/module/eth/get_block_by_hash.go +++ b/module/eth/get_block_by_hash.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +// BlockByHash requests the block with full transactions with the given hash. func BlockByHash(hash common.Hash) *BlockByHashFactory { return &BlockByHashFactory{hash: hash} } @@ -58,6 +59,7 @@ func (f *BlockByHashFactory) HandleResponse(elem rpc.BatchElem) error { return nil } +// HeaderByHash requests the header with the given hash. func HeaderByHash(hash common.Hash) *HeaderByHashFactory { return &HeaderByHashFactory{hash: hash} } diff --git a/module/eth/get_block_by_number.go b/module/eth/get_block_by_number.go index c2db3191..358b3361 100644 --- a/module/eth/get_block_by_number.go +++ b/module/eth/get_block_by_number.go @@ -8,6 +8,8 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +// BlockByNumber requests the block with full transactions with the given +// number. func BlockByNumber(number *big.Int) *BlockByNumberFactory { return &BlockByNumberFactory{number: number} } @@ -58,6 +60,7 @@ func (f *BlockByNumberFactory) HandleResponse(elem rpc.BatchElem) error { return nil } +// HeaderByNumber requests the header with the given number. func HeaderByNumber(number *big.Int) *HeaderByNumberFactory { return &HeaderByNumberFactory{number: number} } diff --git a/module/eth/get_transaction_by_hash.go b/module/eth/get_transaction_by_hash.go index 1674d751..48f8870e 100644 --- a/module/eth/get_transaction_by_hash.go +++ b/module/eth/get_transaction_by_hash.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +// TransactionByHash requests the transaction with the given hash. func TransactionByHash(hash common.Hash) *TransactionByHashFactory { return &TransactionByHashFactory{hash: hash} } diff --git a/module/eth/get_transaction_receipt.go b/module/eth/get_transaction_receipt.go index 98263996..801fae85 100644 --- a/module/eth/get_transaction_receipt.go +++ b/module/eth/get_transaction_receipt.go @@ -6,6 +6,8 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +// TransactionReceipt requests the receipt of the transaction with the given +// hash. func TransactionReceipt(hash common.Hash) *TransactionReceiptFactory { return &TransactionReceiptFactory{hash: hash} }