Tezos RPC node client covering the full Tezos RPC specification. All API groups are exposed as interfaces for easy mocking in tests.
go get github.com/dipdup-io/go-lib/nodeimport "github.com/dipdup-io/go-lib/node"
rpc := node.NewMainRPC("https://rpc.tzkt.io/mainnet")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
block, err := rpc.Block(ctx, "head")
if err != nil {
panic(err)
}
log.Printf("%+v", block)| Constructor | Description |
|---|---|
NewRPC(url, chain) |
Full client with explicit chain ID |
NewMainRPC(url) |
Shorthand for mainnet (chain = "main") |
NewMainBlockRPC(url) |
Block API only |
NewMainChainRPC(url) |
Chain API only |
NewMainContextRPC(url) |
Context API only |
The RPC struct composes all groups. Each group can also be instantiated independently if you need only part of the API.
block, err := rpc.Block(ctx, "head") // latest block
block, err := rpc.Block(ctx, "1234567") // by level
block, err := rpc.Block(ctx, "<hash>") // by hash
ops, err := rpc.BlockOperations(ctx, "head")
hash, err := rpc.BlockHash(ctx, "head")chainID, err := rpc.ChainID(ctx)
checkpoint, err := rpc.Checkpoint(ctx)storage, err := rpc.ContractStorage(ctx, "head", "KT1...")
delegate, err := rpc.Delegate(ctx, "head", "tz1...")
delegates, err := rpc.Delegates(ctx, "head")
constants, err := rpc.Constants(ctx, "head")protocol, err := rpc.Protocol(ctx, "head")
protocols, err := rpc.Protocols(ctx)peers, err := rpc.Peers(ctx)
conns, err := rpc.Connections(ctx)
stat, err := rpc.Stat(ctx)hash, err := rpc.InjectOperation(ctx, signedBytes)Each API group has a corresponding interface. Use them in your own structs to enable substitution in tests:
type MyIndexer struct {
rpc node.BlockAPI
}Available interfaces: BlockAPI, ChainAPI, ContextAPI, ConfigAPI, GeneralAPI, ProtocolsAPI, NetworkAPI, InjectAPI, RpcAPI (all-in-one).
Generate mocks with mockgen:
mockgen -source=node/interface.go -destination=mocks/node_mock.go