A client library for the NKN OpenAPI written in go
NKN OpenAPI is an NKN blockchain database abstraction with a neat query interface.
package main
import (
"fmt"
"log"
client "github.com/omani/nkn-openapi-client"
)
func checkerr(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
c := client.New()
c.SetAddress("https://openapi.nkn.org/api/v1")
resp, err := c.GetRegisteredNames()
checkerr(err)
for _, n := range resp.Data {
fmt.Println(n.Name)
}
if !resp.HasMore() {
return
}
// we have more than one page. fetch one more page.
err = c.Next(resp)
checkerr(err)
for _, n := range resp.Data {
fmt.Println(n.Name)
}
}
Unit tests are available in client_test.go
:
Run the tests in the root of the repository with go test
.
go install github.com/omani/nkn-openapi-client/cmd/nkn-openapi-client@latest
git clone https://github.com/omani/nkn-openapi-client
cd cmd/nkn-openapi-client/
go run main.go transactions --address NKNJ6Tka2rcrqT4FPJTjfoWQLjvahctSiyRF
Output:
cd cmd/nkn-openapi-client/
go run main.go transactions --hash 993a8f8ec9ca3a295e8873c573759d11b844c698e0e50f4edd1fa50751c2d879
cd cmd/nkn-openapi-client/
go run main.go blocks --height 5648381
cd cmd/nkn-openapi-client/
go run main.go blocks --hash 0d48328a5005e7455c6a5e2a0b5bc346b09fbae129f1775589be83657850656a
cd cmd/nkn-openapi-client/
go run main.go --url https://my-own-nkn-openapi.tld blocks --hash 0d48328a5005e7455c6a5e2a0b5bc346b09fbae129f1775589be83657850656a
- You can fork this, extend it and contribute back.
- You can contribute with pull requests.
I accept payments and donations in BTC:
bc1qgezvfp4s0xme8pdv6aaqu9ayfgnv4mejdlv3tx
MIT License