项目作者: incognitochain

项目描述 :
Go Incognito SDK
高级语言: Go
项目地址: git://github.com/incognitochain/go-incognito-sdk.git
创建时间: 2020-12-24T10:11:05Z
项目社区:https://github.com/incognitochain/go-incognito-sdk

开源协议:GNU General Public License v3.0

下载


Incognito SDK

This is SDK support integration with a chain. That mean you creating wallet, sending token, staking node, trading,
etc… with Incognito blockchain.

Use

Incognito SDK use as library

Installation

Using go module

  1. go get github.com/incognitochain/go-incognito-sdk@new-tag
Initialization

Init new PublicIncognito, setup endpoint url environment

Testnet: https://testnet.incognito.org/fullnode

  1. client := &http.Client{}
  2. publicIncognito := NewPublicIncognito(client, "https://testnet.incognito.org/fullnode")

To create new wallet init new Wallet Object

  1. blockInfo := NewBlockInfo(publicIncognito)
  2. wallet := NewWallet(publicIncognito, blockInfo)
  3. //create new wallet
  4. wallet.CreateWallet()
  5. //send token
  6. wallet.SendToken(....)
  7. //get balance
  8. wallet.GetBalance(...)

To staking a node

  1. stake = NewStake(publicIncognito)
  2. //list unstake
  3. stake.ListUnstake()
  4. //get reward amount of node
  5. stake.GetRewardAmount(

To get blockchain info

  1. //get blockchain info
  2. blockInfo.GetChainInfo()
  3. //get best block height of chain
  4. blockInfo.GetBestBlockHeight(...)
All together
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/incognitochain/go-incognito-sdk/incognitoclient"
  5. "github.com/incognitochain/go-incognito-sdk/incognitoclient/entity"
  6. "net/http"
  7. )
  8. func main() {
  9. client := &http.Client{}
  10. publicIncognito := NewPublicIncognito(client, "https://testnet.incognito.org/fullnode")
  11. blockInfo := NewBlockInfo(publicIncognito)
  12. wallet := NewWallet(publicIncognito, blockInfo)
  13. //create new a wallet
  14. paymentAddress, pubkey, readonlyKey, privateKey, validatorKey, shardId , _ := wallet.CreateWallet()
  15. fmt.Println("payment adresss", paymentAddress)
  16. fmt.Println("public key", pubkey)
  17. fmt.Println("readonly key", readonlyKey)
  18. fmt.Println("private key", privateKey)
  19. fmt.Println("validator key", validatorKey)
  20. fmt.Println("shard id", shardId)
  21. //send Prv token
  22. //send prv
  23. tx, err := wallet.SendToken(
  24. "112t8s4Pdng512MhHmLVJNYqzoEJQ1TG4XZduvjfwYZFJhmuNtGPhUYRko4jSPFBFmeRg6bumKQuhAEMriQ72cpp5SKAkRuXfLCv5xeZx3f5",
  25. "12Rsf3wFnThr3T8dMafmaw4b3CzUatNao61dkj8KyoHfH5VWr4ravL32sunA2z9UhbNnyijzWFaVDvacJPSRFAq66HU7YBWjwfWR7Ff",
  26. publicIncognito.GetPRVToken(),
  27. 500000000000,
  28. 5,
  29. "",
  30. )
  31. if err != nil {
  32. fmt.Println(err.Error())
  33. return
  34. }
  35. fmt.Println(tx)
  36. amountPrv, err := wallet.GetBalance("112t8s4Pdng512MhHmLVJNYqzoEJQ1TG4XZduvjfwYZFJhmuNtGPhUYRko4jSPFBFmeRg6bumKQuhAEMriQ72cpp5SKAkRuXfLCv5xeZx3f5", publicIncognito.GetPRVToken())
  37. fmt.Println(amountPrv)
  38. }

How to works

Incognito SDK wrap all RPC of blockchain, build raw data at device local before call rpc because maybe have issue when send private key to FullNode

The steps:

  1. Build raw data at device local
  2. Call RPC with raw data
  3. Get result

UML Diagram

Screenshot

Godoc

  • With Docker
  1. docker build -t godoc-sdk .
  2. docker run -p 6060:6060 --name godoc-sdk godoc-sdk
  • Without Docker
  1. godoc -http=:6060

Access endpoint

http://localhost:6060/pkg/github.com/incognitochain/go-incognito-sdk/incognitoclient