It follows the official Dart SDK code structure. Tested with Go v1.18. It is 100% compatible with go-zenon.
The Go SDK features a client that will connect to a Zenon full node via websockets. We recommend setting up and running a local Zenon full node.
Install Go v1.18 and start the latest znnd node version on your local host. By default the RPC calls are enabled, otherwise please check the config.json.
Some RPC calls require the keyFile to modify the state of the ledger for example moving funds, while others only read the on-chain data such as getting the latest momentum or a particular account-block.
- Note that there must be a valid
keyFilewith the specified name inDefaultWalletDir. The name of thekeyFilecan be specified by the user, otherwise by default it is thebaseAddress.
// Load your keyFile (wallet file)
z, err := zenon.NewZenon("keyfile-sdk")
if err != nil {
zenon.CommonLogger.Error("", err)
}
// Connect to local node and decrypt your wallet from defaultKeyFilePath
if err := z.Start("123456", "ws://127.0.0.1:35998", 0); err != nil {
zenon.CommonLogger.Error("", err)
}
// Issue RPC calls to the node
// Stop the client
if err := z.Stop(); err != nil {
zenon.CommonLogger.Error("", err)
}- Calls that can be issued without a
keyFile. Note that calls that require akeyFilecannot be used.
// Initialize zenon client (without keyFile)
z, err := zenon.NewZenon("")
if err != nil {
zenon.CommonLogger.Error("", err)
}
// Connect to local node
if err := z.Start("", "ws://127.0.0.1:35998", 0); err != nil {
zenon.CommonLogger.Error("", err)
}
// Issue RPC calls to the node
// Stop the client
if err := z.Stop(); err != nil {
zenon.CommonLogger.Error("", err)
}keyFile, err := wallet.ReadKeyFile("keyfile-sdk", "123456")
if err != nil {
fmt.Printf("err: %s\n", err)
} else {
fmt.Printf("baseAddress: %s\n", keyFile.BaseAddress)
_, kp, err := keyFile.DeriveForIndexPath(0)
if err != nil {
fmt.Printf("err: %s\n", err)
} else {
fmt.Printf("kp address: %s\n", kp.Address.String())
}
}kf, err := wallet.NewKeyFile()
if err != nil {
zenon.WalletLogger.Error("", err)
} else {
if err := wallet.WriteKeyFile(kf, "keyfile-sdk", "123456"); err != nil {
zenon.WalletLogger.Error("", "wallet", err)
}
}- Note that you must fill in the
ZnnTokenStandardaccordingly forZNN,QSRorZTS
if err := z.Send(z.Client.LedgerApi.SendTemplate(toAddress, types.ZnnTokenStandard, amount, []byte{})); err != nil {
fmt.Println(err)
}
if err := z.Send(z.Client.LedgerApi.ReceiveTemplate(types.HexToHashPanic("HASH"))); err != nil {
fmt.Println(err)
}if err := z.Send(z.Client.PillarApi.Register("keyfile-sdk", z.Address(), z.Address(), 0, 50)); err != nil {
fmt.Println(err)
}if err := z.Send(z.Client.PillarApi.UpdatePillar("keyfile-sdk", types.ParseAddressPanic("z1qqmqp78duzxhpvg7dwxph7724mqu2t3mru297p"), z.Address(), 10, 10)); err != nil {
fmt.Println(err)
}z.Send(z.Client.PillarApi.Delegate("Pillar"))z.Send(z.Client.PillarApi.Undelegate())amount := big.NewInt(50000 * constants.Decimals)
if err := z.Send(z.Client.SentinelApi.DepositQsr(amount)); err != nil {
fmt.Println(err)
}if err := z.Send(z.Client.SentinelApi.WithdrawQsr()); err != nil {
fmt.Println(err)
}if err := z.Send(z.Client.SentinelApi.Register()); err != nil {
fmt.Println(err)
}if err := z.Send(z.Client.SentinelApi.Revoke()); err != nil {
fmt.Println(err)
}if err := z.Send(z.Client.PlasmaApi.Fuse(toAddress, amount)); err != nil {
fmt.Println(err)
}amount := big.NewInt(15000 * constants.Decimals)
if err := z.Send(z.Client.StakeApi.Stake(6*30*24*60*60, amount)); err != nil {
fmt.Println(err)
}totalSupply := big.NewInt(15000 * constants.Decimals)
maxSupply := big.NewInt(20000 * constants.Decimals)
if err := z.Send(z.Client.TokenApi.IssueToken("keyfile-sdk", "SDK test", "sdk-test.com", totalSupply, maxSupply, 8, true, true, true)); err != nil {
fmt.Println(err)
}tokenZts, _ := types.ParseZTS("ZTS")
if err := z.Send(z.Client.TokenApi.Mint(tokenZts, amount, z.Address())); err != nil {
fmt.Println(err)
}amount := big.NewInt(1250 * constants.Decimals)
tokenZts, _ := types.ParseZTS("ZTS")
if err := z.Send(z.Client.TokenApi.Burn(tokenZts, amount)); err != nil {
fmt.Println(err)
}tokenZts, _ := types.ParseZTS("ZTS")
if err := z.Send(z.Client.TokenApi.UpdateToken(tokenZts, z.Address(), false, false)); err != nil {
fmt.Println(err)
}amountZnn := big.NewInt(5000 * constants.Decimals)
amountQsr := big.NewInt(50000 * constants.Decimals)
if err := z.Send(z.Client.AcceleratorApi.CreateProject("sdk-project-test", "sdk test description", "github.com/sdk/test", amountZnn, amountQsr)); err != nil {
fmt.Println(err)
}