RPC Client
w3.Client
is a blazing fast RPC client build on top of go-ethereum/rpc.Client
. It is designed for batch requests and easy extendibility.
Get Started
w3.Client
is a batch request focused RPC client that can be used to connect to an Ethereum node via HTTP, WebSocket, or IPC. Its modular API allows to create custom RPC method integrations that can be used alongside the common methods implemented by this package.
Connect to an RPC Endpoint
Connect to an RPC endpoint via HTTP, WebSocket, or IPC using w3.Dial
or w3.MustDial
.
client, err := w3.Dial("https://rpc.ankr.com/eth")
if err != nil {
// ...
}
defer client.Close()
Make a Request
Make a single HTTP request that calls two RPC methods.
var (
balance *big.Int
nonce uint64
)
if err := client.Call(
eth.Balance(addr, nil).Returns(&balance),
eth.Nonce(addr, nil).Returns(&nonce),
); err != nil {
// ...
}
Why send batch requests?
Most of the time you need to call multiple RPC methods to get the data you need. When you make separate requests per RPC call you need a single round trip to the server for each call. This can be slow, especially for remote endpoints. Batching multiple RPC calls into a single request only requires a single round trip, and speeds up RPC calls significantly.