WikiChain Offline Wallet Tools SDK (WaykiChain Offline Wallet Utilities SDK)

Go wallet Utilities

WikiChain go language offline signature wallet library (WaykiChain Wallet Library for Offline Operation written in Golang)



Download (Install)

Go: check your GOPATH

go env GOROOT GOPATH

Results

/usr/local/Cellar/go/1.13.1/libexec
/Users/automac/Documents/go/

Download the go wallet library in the GOPATH/src/github.com/

go get -u git@github.com:WaykiChain/wicc-wallet-utils-go

Download the btcsuit btcd to GOPATH/src/github.com/

go get -u github.com/btcsuite/btcutil

Download the btcd GOPATH/src/github.com/

go get -u github.com/btcsuite/btcd

git clone

go get $GOPATH https://github.com/WaykiChain/wicc-wallet-utils-go)
go get $GOPATH https://github.com/btcsuite


Usage (Usage)

Create Wallet (WaykiChain Create Wallet) Generate mnemonics and private keys to manage your wallet. Generate mnemonics and private keys to manage your wallet.

func GenerateMnemonics() string

func GetPrivateKeyFromMnemonic(words string, netType int) string

func GetPubKeyFromPrivateKey(privKey string) (string,error)

func GetAddressFromPrivateKey(privateKey string, netType int) string

func GetAddressFromMnemonic(words string, netType int) string
  • GenerateMnemonics. Generate 12 mnemonics (You will get 12 words).

  • GetPrivateKeyFromMnemonic.

You provide your mnemonic and network type (1 main network, 2 test network), the function will return you the private key, the main network private key uppercase P begins, the test network uppercase Y begins. (You should provide your mnemonic and network Type (1 MainNet, 2 TestNet), function return private Key, MainNet Private key start with "P" , TestNet private key start with "Y".)

  • GetPubKeyFromPrivateKey.

(Provide the private key to get the public key and get the hexadecimal string of the public key) You should provide your Private Key, the function return wallet public key as hex string.

  • GetAddressFromPrivateKey.

The private key obtains the wallet address, the address is a Base58 encoded string, the primary network address begins with the uppercase letter W, and the test network address begins with the lowercase letter w. You should provide your Private Key, the function return wallet Address as base58 encode string,MainNet Address start with "W",TestNet Address start with "w".

  • GetAddressFromMnemonic.

Get the address from the mnemonic. You should provide your mnemonic, the function return wallet Address as base58 encode string,MainNet Address start with "W",TestNet Address start with "w".

Examples:

Generate mnemonic

Mnemonic := GenerateMnemonics()

Get private key from mnemonic

Mnemonic := "empty regular curve turtle student prize toy accuse develop spike scatter ginger"
privateKey := GetPrivateKeyFromMnemonic(mnemonic, WAYKI_MAINTNET)

Get public key from private key

publicKey,_:=GetPubKeyFromPrivateKey("Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13")

Get address from private key

Address := GetAddressFromPrivateKey(privateKey, WAYKI_MAINTNET)

Get address from mnemonic

Mnemonic := "empty regular curve turtle student prize toy accuse develop spike scatter ginger"
Address := GetAddressFromMnemonic(mnemonic, WAYKI_MAINTNET)

WaykiChain Chain Signing Transaction (WaykiChain Sign Transaction)

To sign a transaction with a private key, you can use bass to submit the rawtx string generated by the wallet library. Signing a transaction with a private key, you can submit your offline signature rawtx transaction by bass.

BassNetwork ApiAddr
TestNetwork https://baas-test.wiccdev.org/v2/api/swagger-ui.html#!/
ProdNetwork https://baas.wiccdev.org/v2/api/swagger-ui.html#!/

Submit raw string:

Mainnet https://baas.wiccdev.org/v2/api/swagger-ui.html#!/transaction-controller/offlinTransactionUsingPOST ,

TestNet https://baas-test.wiccdev.org/v2/api/swagger-ui.html#!/transaction-controller/offlinTransactionUsingPOST,

Get block height:

MainNethttps://baas.wiccdev.org/v2/api/swagger-ui.html#!/block-controller/getBlockCountUsingPOST,

TestNet https://baas-test.wiccdev.org/v2/api/swagger-ui.html#!/block-controller/getBlockCountUsingPOST


Common transaction

WICC Transaction Unit description

func SignRegisterAccountTx(privateKey string, param *RegisterAccountTxParam) (string, error)

func SignCommonTx(privateKey string, param *CommonTxParam) (string, error)

func SignDelegateTx(privateKey string, param *DelegateTxParam) (string, error)

func SignCallContractTx(privateKey string, param *CallContractTxParam) (string, error)

func SignRegisterContractTx(privateKey string, param *RegisterContractTxParam) (string, error)

func SignUCoinTransferTx(privateKey string, param *UCoinTransferTxParam) (string, error)
  • SignRegisterAccountTx. Wallet registration transaction Sign registration transaction with a private key , return the rawtx string.

  • SignCommonTx. General transfer transaction Sign transfer transaction with a private key , return the rawtx string.

  • SignDelegateTx. Voting transaction Sign delegate transaction with a private key , return the rawtx string.

  • SignCallContractTx. Call contract transaction Sign invoke contract transaction with a private key , return the rawtx string.

  • SignRegisterContractTx. Contract deployment transaction Sign deploy contract transaction with a private key , return the rawtx string.

  • SignUCoinTransferTx. Multi-currency transfer Sign Multi-coin transfer transaction with a private key , return the rawtx string.

Example

Wallet registration transactions are no longer necessary and you can activate them in other transactions via public key parameters.

NOTE The register transaction is not required, you can activate wallet by public key in other transactions

Sign register account transaction:

privateKey := "YAa1wFCfFnZ5bt4hg9MDeDevTMd1Nu874Mn83hEXwtfAL2vkQE9f"
Var txParam RegisterAccountTxParam
txParam.ValidHeight = 630314 //WaykiChain block height
txParam.Fees = 10000 //Miner fee,minimum 10000sawi

Hash, err := SignRegisterAccountTx(privateKey, &txParam)
If err != nil {
t.Error("SignRegisterAccountTx err: ", err)
}

Sign common transfer transaction

    privateKey := "YAa1wFCfFnZ5bt4hg9MDeDevTMd1Nu874Mn83hEXwtfAL2vkQE9f"
Var txParams CommonTxParam
txParams.ValidHeight = 630314
txParams.SrcRegId = "158-1" //user regid
txParams.DestAddr = "wSSbTePArv6BkDsQW9gpGCTX55AXVxVKbd" //dest address
txParams.Values ​​= 10000 //transfer amount
txParams.Fees = 10000
txParams.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7" //wallet public key hex string
    txParams.Memo="test transfer" //transfer memo
Hash, err := SignCommonTx(privateKey, &txParams)
If err != nil {
t.Error("SignCommonTx err: ", err)
}

Sign Multi-coin transfer transaction:

    //CointSymbol:Supported (WICC WUSD WGRT)
    //FeeSymbol:Supported (WICC WUSD WGRT)
    privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam UCoinTransferTxParam
txParam.FeeSymbol = string(commons.WICC)
txParam.CoinSymbol = string(commons.WICC)
txParam.CoinAmount = 1000000
txParam.Fees = 10000
txParam.ValidHeight = 297449
txParam.SrcRegId = "0-1"
txParam.DestAddr = "wNDue1jHcgRSioSDL4o1AzXz3D72gCMkP6"
txParam.PubKey = "036c5397f3227a1e209952829d249b7ad0f615e43b763ac15e3a6f52627a10df21"
txParam.Memo = ""
Hash, err := SignUCoinTransferTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}

Sign Delegate transaction

    privateKey := "Y9sx4Y8sBAbWDAqAWytYuUnJige3ZPwKDZp1SCDqqRby1YMgRG9c"
Var txParams DelegateTxParam
txParams.ValidHeight = 95728
txParams.SrcRegId = "0-1"
txParams.Fees = 10000
txParams.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"
txParams.Votes = NewOperVoteFunds()
pubKey, _ := hex.DecodeString("025a37cb6ec9f63bb17e562865e006f0bafa9afbd8a846bd87fc8ff9e35db1252e") //Voted public key
Vote := OperVoteFund{PubKey: pubKey, VoteValue: 10000}
txParams.Votes.Add(&vote)

Hash, err := SignDelegateTx(privateKey, &txParams)
If err != nil {
t.Error("SignDelegateTx err: ", err)
}

Sign invoke contract transaction

privateKey := "Y9sx4Y8sBAbWDAqAWytYuUnJige3ZPwKDZp1SCDqqRby1YMgRG9c"
Var txParam CallContractTxParam
txParam.ValidHeight = 22365
txParam.SrcRegId = "0-1"
txParam.AppId = "20988-1" //contract regid
txParam.Fees = 100000
txParam.Values ​​= 10000
txParam.ContractHex = "f017" //call contract method
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"
Hash, err := SignCallContractTx(privateKey, &txParam)
If err != nil {
t.Error("SignCallContractTx err: ", err)
}

Sign deploy contract Transaction

privateKey := "YAa1wFCfFnZ5bt4hg9MDeDevTMd1Nu874Mn83hEXwtfAL2vkQE9f"
Script, err := ioutil.ReadFile("./demo/data/hello.lua")
If err != nil {
t.Error("Read contract script file err: ", err)
}
Var txParam RegisterContractTxParam
txParam.ValidHeight = 630314
txParam.SrcRegId = "0-1"
txParam.Fees = 110000000 //Miner fee,minimum 11000000sawi
txParam.Script = script //contract bytearray
txParam.Description = "My hello contract!!!" //contract description
Hash, err := SignRegisterContractTx(privateKey, &txParam)
If err != nil {
t.Error("SignRegisterContractTx err: ", err)
}


CDP Transaction

Users can obtain WUSD by mortgage WICC, a user can only have one cdp, unless the previous cdp has been closed. Any user holding a WICC can send a WICC to the CDP (Collaterized Debt Position) to obtain a certain percentage of WUSD.a user can only have one cdp unless the previous cdp has been destroyed.

func SignCdpStakeTx(privateKey string, param *CdpStakeTxParam) (string, error)

func SignCdpRedeemTx(privateKey string, param *CdpRedeemTxParam) (string, error)

func SignCdpLiquidateTx(privateKey string, param *CdpLiquidateTxParam) (string, error)
  • SignCdpStakeTx. CDP mortgage transaction signature. Sign cdp stake transaction with a private key , return the rawtx string.

  • SignCdpRedeemTx. Cdp redeem the transaction signature. Sign cdp redeem transaction with a private key , return the rawtx string.

  • SignCdpLiquidateTx. CDP clearing transaction signature. Sign cdp liquidate transaction with a private key , return the rawtx string.

Example

Sign cdp stake transaction:

    privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam CdpStakeTxParam
txParam.CdpTxid = "0b9734e5db3cfa38e76bb273dba4f65a210cc76ca2cf739f3c131d0b24ff89c1" //user cdp transaction hash,If the user has not created a cdp, then do not fill out
txParam.BcoinSymbol = string(commons.WICC) ​​//pay WICC
txParam.ScoinSymbol = string(commons.WUSD) //get WUSD
txParam.FeeSymbol = string(commons.WICC) ​​//fee symbol (WICC/WUSD)
txParam.BcoinStake = 100000000
txParam.ScoinMint = 50000000
txParam.Fees = 100000 //Miner fee,minimum 100000sawi
txParam.ValidHeight = 283308
txParam.SrcRegId = "0-1"
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"

Hash, err := SignCdpStakeTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}

Sign cdp redeem transaction:

    privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam CdpRedeemTxParam
txParam.CdpTxid = "0b9734e5db3cfa38e76bb273dba4f65a210cc76ca2cf739f3c131d0b24ff89c1"//user cdp create transaction hash
txParam.FeeSymbol = string(commons.WICC)
txParam.ScoinsToRepay = 20000000
txParam.BcoinsToRedeem = 100000000
txParam.Fees = 100000 //Miner fee,minimum 100000sawi
txParam.ValidHeight = 25
txParam.SrcRegId = "0-1"
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"

Hash, err := SignCdpRedeemTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}

Sign cdp liquidate transaction:

    privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam CdpLiquidateTxParam
txParam.CdpTxid = "0b9734e5db3cfa38e76bb273dba4f65a210cc76ca2cf739f3c131d0b24ff89c1"//Liquidated cdp transaction hash id
txParam.FeeSymbol = string(commons.WICC)
txParam.ScoinsLiquidate = 100000000
txParam.Fees = 100000 //Miner fee,minimum 100000sawi
txParam.ValidHeight = 25
txParam.SrcRegId = "0-1"
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"

Hash, err := SignCdpLiquidateTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}


DEX Transaction

WaykiChain decentralized exchange.

func SignDexSellLimitTx(privateKey string, param *DexLimitTxParam) (string, error)

func SignDexMarketSellTx(privateKey string, param *DexMarketTxParam) (string, error)

func SignDexBuyLimitTx(privateKey string, param *DexLimitTxParam) (string, error)

func SignDexMarketBuyTx(privateKey string, param *DexMarketTxParam) (string, error)

func SignDexCancelTx(privateKey string, param *DexCancelTxParam) (string, error)
  • SignDexSellLimitTx. Limit sell order. Sign dex sell limit price transaction with a private key , return the rawtx string.

  • SignDexMarketSellTx. Market price sell order. Sign dex sell market price transaction with a private key , return the rawtx string.

  • SignDexBuyLimitTx. Limit purchases. Sign dex buy limit price transaction with a private key , return the rawtx string.

  • SignDexMarketBuyTx. Market price to pay. Sign dex buy market price transaction with a private key , return the rawtx string.

  • SignDexCancelTx. Cancel the pending order. Sign cancel dex order transaction with a private key , return the rawtx string.

Sign dex Buy limit price transaction:

privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam DexLimitTxParam
txParam.FeeSymbol = string(commons.WICC)
txParam.Fees = 100000
txParam.CoinSymbol = string(commons.WUSD)
txParam.AssetSymbol = string(commons.WICC)
txParam.AssetAmount = 10000
txParam.ValidHeight = 25
txParam.Price = 25
txParam.SrcRegId = "0-1"
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"

Hash, err := SignDexBuyLimitTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}

Sign dex sell limit price transaction:

    privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam DexLimitTxParam
txParam.FeeSymbol = string(commons.WICC)
txParam.Fees = 10000
txParam.CoinSymbol = string(commons.WUSD)
txParam.AssetSymbol = string(commons.WICC)
txParam.AssetAmount = 1000000
txParam.ValidHeight = 282956
txParam.Price = 200000000
txParam.SrcRegId = "0-1"
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"

Hash, err := SignDexSellLimitTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}

Sign dex buy market price transaction:

    privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam DexMarketTxParam
txParam.FeeSymbol = string(commons.WICC)
txParam.Fees = 100000
txParam.CoinSymbol = string(commons.WUSD)
txParam.AssetSymbol = string(commons.WICC)
txParam.AssetAmount = 10000
txParam.ValidHeight = 25
txParam.SrcRegId = "0-1"
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"

Hash, err := SignDexMarketBuyTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}

Sign dex cancel order transaction:

privateKey := "Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13"
Var txParam DexCancelTxParam
txParam.FeeSymbol = string(commons.WICC)
txParam.Fees = 100000
txParam.DexTxid = "009c0e665acdd9e8ae754f9a51337b85bb8996980a93d6175b61edccd3cdc144"//dex transaction tx id
txParam.ValidHeight = 25
txParam.SrcRegId = "0-1"
txParam.PubKey = "03e93e7d870ce6f1c9997076c56fc24e6381c612662cd9a5a59294fac9ba7d21d7"

Hash, err := SignDexCancelTx(privateKey, &txParam)
If err != nil {
t.Error("SignCdpStakeTx err: ", err)
}