Nectarflower-go, nectar without nectar 2
Similar to my nectaflower-js library that I made for this post Use Nectar without using Hive-Nectar. I decided to show that what I'm working on can be incredibly useful to the hive community even those that wouldn't make use of hive-nectar.
So here is my attempt at the nectarflower-go library to make use of the json metadata from @nectarflower, that is updated hourly!
package main
import (
"fmt"
"log"
"github.com/thecrazygm/nectarflower-go/hive"
)
func main() {
// Create a client just to fetch nodes
client := hive.NewClient()
// Get nodes from account
nodeData, err := client.GetNodesFromAccount("nectarflower")
if err != nil {
log.Fatalf("Error fetching nodes: %v", err)
}
// Print the list of passing nodes
fmt.Println("Passing nodes:")
for _, node := range nodeData.Nodes {
fmt.Println(node)
}
}
But in order to make it work, it had to have a working client, so that is included as well, it's fairly crude, but does function. Here is an example of it grabbing the block 10 back from current head.
// Create a client
client := hive.NewClient()
// Get the current block number
var props map[string]any
err := client.Call("database_api.get_dynamic_global_properties", nil, &props)
if err != nil {
log.Fatalf("Error fetching global properties: %v", err)
}
// Convert to int64
currentBlockNum, ok := props["head_block_number"].(float64)
if !ok {
log.Fatalf("Error getting block number")
}
// Fetch a specific block
targetBlockNum := int64(currentBlockNum) - 10
blockParams := map[string]any{
"block_num": targetBlockNum,
}
var block map[string]any
err = client.Call("block_api.get_block", blockParams, &block)
if err != nil {
log.Fatalf("Error fetching block: %v", err)
}
// Access block data
blockData, ok := block["block"].(map[string]any)
if ok {
fmt.Printf("Block ID: %v\n", blockData["block_id"])
}
If you want to see the full example, it's in the github.
I'll continue doing what I love and hope that it maybe helps someone else out there. Plus, it's always great to learn new things, and I've been learning golang slowly over the last year or so. This just gave me a proper foot in the behind to get better at it.
As usual,
Michael Garcia a.k.a. TheCrazyGM
Leave Nectarflower-go, nectar without nectar 2 to:
Read more #dev posts
Best Posts From Michael Garcia
We have not curated any of thecrazygm's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Michael Garcia
- An Accidental Stress Test for Hive-Engine Data Integrity
- Fixing Data Integrity Issues in Hive-Engine Nodes
- The Final Chapter: dCity's 70,000 HIVE Claimdrop Has Been Distributed!
- Anther v0.1.0: A Modern Go SDK for Building on Hive
- Redesigning the Project Builder (GET FEATURED!)
- HiveTools Workbench: A Week of Polish, Pollen, and Splinterlands Wallets
- Pollen: A Safer, Cleaner Path Forward for Hive JavaScript Developers
- NectarPay Is Live, and Solana USDC Payments Are Working
- NectarPay Needs One Brave Hive Account Tester
- Lightning Strikes Twice: Upbit Triggers a 45-Million Hive Mega-Pump