mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
rpc: fix example comment and handle Dial error
This commit is contained in:
parent
6492751355
commit
8fbd4f396e
1 changed files with 6 additions and 2 deletions
|
|
@ -28,7 +28,7 @@ import (
|
||||||
// In this example, our client wishes to track the latest 'block number'
|
// In this example, our client wishes to track the latest 'block number'
|
||||||
// known to the server. The server supports two methods:
|
// known to the server. The server supports two methods:
|
||||||
//
|
//
|
||||||
// eth_getBlockByNumber("latest", {})
|
// eth_getBlockByNumber("latest", false)
|
||||||
// returns the latest block object.
|
// returns the latest block object.
|
||||||
//
|
//
|
||||||
// eth_subscribe("newHeads")
|
// eth_subscribe("newHeads")
|
||||||
|
|
@ -40,7 +40,11 @@ type Block struct {
|
||||||
|
|
||||||
func ExampleClientSubscription() {
|
func ExampleClientSubscription() {
|
||||||
// Connect the client.
|
// Connect the client.
|
||||||
client, _ := rpc.Dial("ws://127.0.0.1:8545")
|
client, err := rpc.Dial("ws://127.0.0.1:8545")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("dial error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
subch := make(chan Block)
|
subch := make(chan Block)
|
||||||
|
|
||||||
// Ensure that subch receives the latest block.
|
// Ensure that subch receives the latest block.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue