A Go client library for the Hive blockchain.

go get github.com/cadawg/hivego
Go Reference 80%+ test coverage Go 1.24+

Features

Quick start

import "github.com/cadawg/hivego"

// Connect to one or more API nodes (automatic failover)
client := hivego.NewClient(
    "https://api.hive.blog",
    "https://api.deathwing.me",
)

// Load a key from WIF once at the boundary
key, err := hivego.KeyPairFromWif("5J...")

// Vote on a post
_, txid, err := client.Broadcast.Vote("voter", "author", "permlink", 10000, key)

// Transfer HIVE
amount, _ := hivego.ParseAsset("1.000 HIVE")
_, txid, err = client.Broadcast.Transfer("alice", "bob", amount, "memo", key)

// Read a block
block, err := client.Database.GetBlock(88000000)
fmt.Println(block.Witness, block.Timestamp.Time())

Supported operations

All operations are available as structs implementing HiveOperation, with convenience methods on client.Broadcast:

Social

  • vote
  • comment
  • comment_options
  • delete_comment

Transfers

  • transfer
  • recurrent_transfer
  • transfer_to_savings
  • transfer_from_savings
  • cancel_transfer_from_savings

Hive Power

  • transfer_to_vesting
  • withdraw_vesting
  • delegate_vesting_shares
  • set_withdraw_vesting_route
  • claim_reward_balance

Market

  • convert
  • collateralized_convert
  • limit_order_create
  • limit_order_cancel

Accounts

  • account_create
  • create_claimed_account
  • claim_account
  • account_update
  • account_update2

Witnesses

  • witness_update
  • witness_set_properties
  • account_witness_vote
  • account_witness_proxy
  • feed_publish

Proposals (DHF)

  • create_proposal
  • update_proposal
  • update_proposal_votes
  • remove_proposal

Recovery & Escrow

  • request_account_recovery
  • recover_account
  • change_recovery_account
  • escrow_transfer
  • escrow_approve
  • escrow_dispute
  • escrow_release

Custom

  • custom_json
  • custom
  • custom_binary
  • decline_voting_rights

Need an operation not listed? Implement the HiveOperation interface and pass it to client.BroadcastOps.

More examples

Multi-operation transactions

// comment + comment_options must be in the same transaction
maxPayout, _ := hivego.ParseAsset("1000000.000 HBD")
ops := []hivego.HiveOperation{
    hivego.CommentOperation{
        Author: "alice", Permlink: "my-post",
        ParentPermlink: "hive-blog",
        Title: "Hello Hive", Body: "...",
        JsonMetadata: `{"tags":["blog"]}`,
    },
    hivego.CommentOptionsOperation{
        Author: "alice", Permlink: "my-post",
        MaxAcceptedPayout: maxPayout,
        PercentHbd: 10000, AllowVotes: true, AllowCurationRewards: true,
        Beneficiaries: []hivego.Beneficiary{{Account: "appdev", Weight: 500}},
    },
}
_, txid, err := client.BroadcastOps(ops, postingKey)

Dry-run / inspect transactions

client := hivego.NewClient("https://api.hive.blog").WithNoBroadcast()

tx, txid, err := client.Broadcast.Vote("voter", "author", "permlink", 10000, key)
fmt.Println("txid:", txid)

b, _ := tx.Serialize()
fmt.Printf("wire: %x\n", b)

Stream blocks

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

blocks, errc := client.Database.StreamBlocks(ctx, 88000000, 3*time.Second)
for block := range blocks {
    fmt.Println(block.BlockID, block.Timestamp.Time())
}
if err := <-errc; err != nil {
    log.Fatal(err)
}

Testnet

client := hivego.NewClient("https://testnet.openhive.network")
client.ChainID = "18dcf0a285365fc58b71f18b3d3fec954aa0c141c44e4e5cb4cf777b9eab274e"
client.PublicKeyPrefix = "TST"

Error handling

// Sentinel errors — use errors.Is
if errors.Is(err, hivego.ErrChecksumMismatch) { ... }
if errors.Is(err, hivego.ErrInvalidAsset)     { ... }

// RPC errors from the node — use errors.As
var rpcErr *hivego.RPCError
if errors.As(err, &rpcErr) {
    fmt.Println(rpcErr.Code, rpcErr.Message)
}