Nano blockchain interaction library.
Features:
- Beginner-friendly functions (Send, Receive, ReceiveAll, ChangeRepresentative).
- Create, sign and process blocks.
- Send useful RPC requests.
- Send custom RPC requests.
- Unit conversion functions.
- Seed, Private Key, Public Key and Address conversion functions.
- Address validation.
You need another feature? Open an issue with the feature request label.
Use go get to install the package.
go get github.com/zenitria/nanogo@latestpackage main
import (
"fmt"
"github.com/zenitria/nanogo"
)
func main() {
// Create a new client
client := nanogo.Client{
Url: "http://localhost:7076",
}
// Send Nano
address := "nano_14kwyg4wxw89orxsxgzgrf14exwa683rmubth4i6uh1dnoir1kb48ip4zwdt"
seed := "D2F1A4C8E7B0E3D5F2A1C8E0B7D3F8A0B2C4E5D7F9C2A3B6D9F3C0A1B2E5D4"
raw, err := nanogo.NanoToRaw("0.01")
if err != nil {
fmt.Println(err)
return
}
hash, err := client.Send(address, raw, seed, 0)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Block hash:", hash)
}For more detailed documentation go to pkg.go.dev
The Client struct is used to interact with the Nano blockchain. It contains the URL of the RPC server, the authorization header and the authorization token.
client := nanogo.Client{
Url: "Nano RPC URL",
AuthHeader: "Authorization header", // if the RPC server requires an authorization
AuthToken: "Authorization token" // if the RPC server requires an authorization
}The Send function sends Nano to an address. It requires the address, the raw amount, the seed and the account index. It returns the block hash or an error.
hash, err := client.Send(address, raw, seed, index)The Receive function receives Nano from a block. It requires the block hash, the source address, the raw amount, the seed and the account index. It returns the block hash or an error.
hash, err := client.Receive(hash, sourceAddress, raw, seed, index)The ReceiveAll function receives all pending Nano. It requires the seed and the account index. It returns the block hashes or an error.
hashes, err := client.ReceiveAll(seed, index)The ChangeRepresentative function changes the representative of an account. It requires the new representative, the seed and the account index. It returns the block hash or an error.
hash, err := client.ChangeRepresentative(representative, seed, index)The RPC function sends a custom RPC request. It requires the data to send. It returns the response or an error.
response, err := client.RPC(data)The GetAccountBalance function gets the balance of an account. It requires the address. It returns the balance or an error.
balance, err := client.GetAccountBalance(address)The GetAccountInfo function gets the information of an account. It requires the address. It returns the account info or an error.
info, err := client.GetAccountInfo(address)The GetAccountHistory function gets the history of an account. It requires the address and the count (use -1 for all). It returns the account history or an error.
history, err := client.GetAccountHistory(address, count)The GetReceivable function gets the receivable blocks of an account. It requires the address. It returns the receivable blocks or an error.
receivable, err := client.GetReceivable(address)The GetRepresentatives function gets the online representatives. It returns the representatives or an error.
representatives, err := client.GetRepresentatives()The GenerateWork function generates a work for a block hash. It requires the block. It returns the work or an error.
work, err := client.GenerateWork(block)The Process function processes a block. It requires the subtype and the block. It returns the block hash or an error.
hash, err := client.Process(subtype, block)The Block struct is used to create and sign blocks. It contains the type, the account, the previous block hash, the representative, the balance, the link, the link as account, the signature and the work.
block := nanogo.Block{
Type: "type",
Account: "wallet address",
Previous: "previous block hash",
Representative: "representative wallet address",
Balance: "new balance in raw",
Link: "link in hex",
LinkAsAccount: "link as a wallet address",
Signature: "block signature", // added after signing (not add manually)
Work: "generated work", // added after generating work (not add manually)
}The Sign function signs a block. It requires the private key. It optionally returns an error.
err := block.Sign(privateKey)The AddWork function adds work to a block. It requires the work.
block.AddWork(work)The SeedToPrivateKey function converts a seed to a private key. It requires the seed and the account index. It returns the private key or an error.
privateKey, err := nanogo.SeedToPrivateKey(seed, index)The PrivateKeyToPublicKey function converts a private key to a public key. It requires the private key. It returns the public key or an error.
publicKey, err := nanogo.PrivateKeyToPublicKey(privateKey)The PublicKeyToAddress function converts a public key to the wallet address. It requires the public key. It returns the address or an error.
address, err := nanogo.PublicKeyToAddress(publicKey)The AddressToPublicKey function converts a wallet address to a public key. It requires the address. It returns the public key or an error.
publicKey, err := nanogo.AddressToPublicKey(address)The NanoToRaw function converts Nano to raw. It requires the amount. It returns the raw amount or an error.
raw, err := nanogo.NanoToRaw(amount)The RawToNano function converts raw to Nano. It requires the raw amount. It returns the amount or an error.
nano, err := nanogo.RawToNano(raw)The AddressIsValid function checks if a wallet address is valid. It requires the address. It returns a boolean.
isValid := nanogo.AddressIsValid(address)