rpc: fix example comment and handle Dial error

This commit is contained in:
Fibonacci747 2025-09-17 18:12:26 +02:00 committed by GitHub
parent 6492751355
commit 8fbd4f396e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,7 +28,7 @@ import (
// In this example, our client wishes to track the latest 'block number'
// known to the server. The server supports two methods:
//
// eth_getBlockByNumber("latest", {})
// eth_getBlockByNumber("latest", false)
// returns the latest block object.
//
// eth_subscribe("newHeads")
@ -40,7 +40,11 @@ type Block struct {
func ExampleClientSubscription() {
// 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)
// Ensure that subch receives the latest block.