https://github.com/omani/nkn-openapi-client
A client library for the NKN OpenAPI written in go
https://github.com/omani/nkn-openapi-client
client go golang nkn openapi resty
Last synced: 6 months ago
JSON representation
A client library for the NKN OpenAPI written in go
- Host: GitHub
- URL: https://github.com/omani/nkn-openapi-client
- Owner: omani
- License: mit
- Created: 2023-08-03T01:00:18.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-05T14:58:45.000Z (over 2 years ago)
- Last Synced: 2025-06-11T10:13:29.115Z (8 months ago)
- Topics: client, go, golang, nkn, openapi, resty
- Language: Go
- Homepage: https://nkn.org/
- Size: 291 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://pkg.go.dev/github.com/omani/nkn-openapi-client)
# nkn-openapi-client
A client library for the [NKN OpenAPI](https://github.com/rule110-io/nkn-open-api) written in go
> NKN OpenAPI is an NKN blockchain database abstraction with a neat query interface.
## Example
```go
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`.
### This repository comes with a simple example CLI app in `cmd/`.
---
## CLI App
### Install
`go install github.com/omani/nkn-openapi-client/cmd/nkn-openapi-client@latest`
### Usage
#### Clone this repository
`git clone https://github.com/omani/nkn-openapi-client`
#### Show transactions of an NKN wallet address:
```
cd cmd/nkn-openapi-client/
go run main.go transactions --address NKNJ6Tka2rcrqT4FPJTjfoWQLjvahctSiyRF
```
Output:

#### Show transactions with a given hash
```
cd cmd/nkn-openapi-client/
go run main.go transactions --hash 993a8f8ec9ca3a295e8873c573759d11b844c698e0e50f4edd1fa50751c2d879
```
#### Show block at a given height
```
cd cmd/nkn-openapi-client/
go run main.go blocks --height 5648381
```
#### Show block with a given hash
```
cd cmd/nkn-openapi-client/
go run main.go blocks --hash 0d48328a5005e7455c6a5e2a0b5bc346b09fbae129f1775589be83657850656a
```
#### Use your own NKN OpenAPI instance by providing a `--url` flag
```
cd cmd/nkn-openapi-client/
go run main.go --url https://my-own-nkn-openapi.tld blocks --hash 0d48328a5005e7455c6a5e2a0b5bc346b09fbae129f1775589be83657850656a
```
---
# Contribution
* You can fork this, extend it and contribute back.
* You can contribute with pull requests.
# Donations
I accept payments and donations in BTC:
`bc1qgezvfp4s0xme8pdv6aaqu9ayfgnv4mejdlv3tx`
# LICENSE
MIT License