RPC
Go Client for the Tezos RPC
Visit the GoDoc docu or read the source code on Github.
The RPC package defines a common client object that wraps a HTTP/TLS connection and offers an extensive list of RPC calls to
query the state of a Tezos node (
GetStatus()
andGetVersionInfo()
)fetch blocks and operations (
GetBlock()
,GetBlockHeader()
,GetBlockOperation()
, etc)fetch mempool contents (
GetMempool()
)monitor for events (
MonitorBlockHeader()
,MonitorMempool()
, etc)query accounts, delegates and contract state (e.g.
GetContract()
,GetDelegate()
,GetContractStorage()
,GetBigmapValue()
, etc)query delegate baking rights, rolls, snapshots
query voting data such as lists of voters, ballots, proposals and voting stats
run/simulate code, views, operations and broadcast operations
Note that the Tezos RPC uses the term contract for both accounts and smart contracts in its path arguments. To avoid confusion we use the same terminology here.
RPC client
TzGo does not ship a list of public RPC endpoints or a default setting. To create an RPC client you need to provide a URL to either your own node or a public Tezos RPC provider.
Customized RPC
TzGo's rpc.NewClient()
function takes an optional Go http.Client
as parameter which you can configure before or after passing it to the library. The example below shows how to set custom timeouts and disable TLS certificate checks (not recommended in production, but useful if you use self-signed certificates during testing).
Node status
TzGo lets you easily check node status and version
Identifying blocks
Many queries in TzGo's RPC package allow you to select a block to run the query against. That way you can access historic state of accounts, contracts or bigmaps if you execute the query against a full archive node. TzGo provides several ways to express block identity using
rpc.BlockLevel
for block heights (this may be ambiguous during reorgs)rpc.Head
orrpc.Genesis
as alias namesa
tezos.BlockHash
(is best choice)rpc.BlockOffset
to define a positive or negative offset from a given identity
Block contents
Tezos blocks contain receipts for confirmed operations plus some consensus-related metadata. A block's identity is uniquely defined by its block hash. The position inside the chain is defined by the block's level and relations between blocks are expressed by a predecessor hash in each block's metadata. Following predecessor hashes backwards walks the entire chain back in history. Block queries can use different identifiers to select a block (see above).
Operations inside a block are assigned to 4 lists according to their type (0) consensus, (1) voting, (2) special and (3) user transactions. An operation in Tezos contains a common header that defines provenance information plus some non-empty content which may be a single transaction or a list of multiple transactions. Transactions are typed and each type contains data that has been sent and signed by a user's wallet plus metadata that has been added as an execution receipt by the Tezos blockchain. Receipts contain balance updates for transfers and fee payments as well as a result which lists all state changes in response to the execution of a transaction. Some smart contract calls can initiate calls to other contracts. If that's the case, an additional internal result list is present.
TzGo's RPC client offers several functions to query blocks, operations and follow the chain of blocks (a non-exhaustive list):
In addition, TzGo's RPC client supports calls to stream new blocks and mempool data.
Account and contract state
Blocks represent the history of updates, but many applications require the current state of an account or some historic state in the past. Both is possible by using a BlockID, for the current block use the rpc.Head
constant, for a historic block use its hash or level.
Note Tezos RPC paths do not distinguish between end user accounts (tz1/tz2/tz3) and smart contracts (KT1), and account calls are named 'contract'. The TzGo client exports the following functions to query account data.
TzGo supports a few more calls specific to baker accounts which allow you to list baking rights and governance voting
Sending Operations
TzGo supports sending of all operation kinds including batch operations (operation groups). The typical Tezos flow of sending an operation constructed by the codec
or contract
packages is
Fill an operation or group with the desired content
Define a block as anchor (branch) to control the maximum lifetime should the operation remain unconfirmed
Complete the operation by dynamically adding a
reveal
operation to publish the signere's public key if necessarySimulate the operation to identify errors early and to estimate costs (gas and storage)
Fill in costs and fees
Serialize and sign the operation
Inject (broadcast) the signed operation
Wait for confirmation (inclusion in a block plus at least N blocks on top to be reorg safe)
Each step of the process can be executed individually step by step using available methods. Most of the time its, however, more convenient to just call Send()
Call Options
The Send()
and Simulate()
functions on the RPC client take an optional argument CallOptions
as the last parameter which can be used for customizing the behavior per call.
Call Receipts
The execution result of a finalized operation is wrapped into a Receipt
struct
Last updated