/minter-go-sdk

Minter Blockchain Golang SDK https://minter.network (unofficial)

Primary LanguageGoMIT LicenseMIT

Minter Golang SDK

About

Minter Blockchain Golang SDK https://minter.network

Actual for Minter version 1.0.x.

Installing

go get github.com/ValidatorCenter/minter-go-sdk

Updating

go get -u github.com/ValidatorCenter/minter-go-sdk

Using Minter

Create MinterSDK instance.

import m "github.com/ValidatorCenter/minter-go-sdk"

sdk := m.SDK{
		MnAddress: "http://156.123.34.5:8841", // example of a node url
		ChainMainnet: false, // Main=>true, Test=>false
}

Structures for receiving data from the blockchain already have tags: json, bson and gorm. This means that you can immediately write them correctly to a database that uses one of these tags.

GetAddress

Returns the balance of given account and the number of outgoing transaction.

GetAddress("Mx...MinterAddress" string): map[string]float32, int, error

Example
blnc, amnTx, err := sdk.GetAddress("Mxdc7fcc63930bf81ebdce12b3bcef57b93e99a157")

// result blnc: {MTN: 1000000, TESTCOIN: 2000000}
// result amnTx: 134

GetStatus

Returns node status info.

GetStatus(): struct, error

GetMinGas

Returns current min gas price.

GetMinGas(): int64, error

GetValidators

Returns list of active validators.

GetValidators(): struct, error

GetValidatorsBlock

Returns a list of validators of a block by its number.

GetValidatorsBlock("blockNumber" int): struct, error

EstimateCoinBuy

Return estimate of buy coin transaction.

EstimateCoinBuy("coinToBuy" string, "coinToSell" coinToBuy, "valueToBuy" int64): struct, error

EstimateCoinSell

Return estimate of sell coin transaction.

EstimateCoinSell("coinToSell" string, "coinToBuy" string, "valueToSell" int64): struct, error

EstimateTxCommission

Return estimate of commission in GasCoin.

EstimateTxCommission("Mt...hash" string): float32, error

GetCoinInfo

Returns information about coin.

GetCoinInfo("COIN_SYMBOL" string): struct, error

GetBlock

Returns block data at given height.

GetBlock("height" int): struct, error

GetEvents

Returns events at given height.

GetEvents("height" int): struct, error

GetTransaction

Returns transaction info.

GetTransaction("Mt...hash" string): struct, error

GetCandidate

Returns candidate’s info by provided public_key. It will respond with 404 code if candidate is not found.

GetCandidate("Mp..." string): struct, error

GetCandidates

Returns list of candidates.

GetCandidates(): struct, error

NewMnemonic

Returns new seed-phrase.

NewMnemonic(): string, error

AuthMnemonic

CLOSED: Authorization by seed-phrase.

AuthMnemonic("seed-phrase" string): "address" string, "private-key" string, error

GetAddressPrivateKey

Returns address of the wallet by provided private key.

GetAddressPrivateKey("private-key" string): "Mx..." string, error

GetVAddressPubKey

Returns validator-address by provided public key.

GetVAddressPubKey("Mp..." string): string

Sign transaction

Returns a signed tx

Example
  • Sign the SendCoin transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	sndDt := m.TxSendCoinData{
		Coin:      "MNT",
		ToAddress: "Mxe64baa7d71c72e6914566b79ac361d139be22dc7",
		Value:     10,
		GasCoin:   "MNT",
		GasPrice:  1,
	}

	resHash, err := sdk.TxSendCoin(&sndDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the MultiSendCoin transaction (max=100tx).
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "...",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	cntList := []m.TxOneSendCoinData{}

	// First address
	cntList = append(cntList, TxOneSendCoinData{
		Coin:      "MNT",
		ToAddress: "Mxe64baa7d71c72e6914566b79ac361d139be22dc7", //Кому переводим
		Value:     10,
	})

	// Second address
	cntList = append(cntList, TxOneSendCoinData{
		Coin:      "VALIDATOR",
		ToAddress: "Mxe64baa7d71c72e6914566b79ac361d139be22dc7", //Кому переводим
		Value:     16,
	})

	mSndDt := m.TxMultiSendCoinData{
		List:     cntList,
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxMultiSendCoin(&mSndDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the SellCoin transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	slDt := m.TxSellCoinData{
		CoinToSell:  "MNT",
		CoinToBuy:   "ABCDEF24",
		ValueToSell: 10,
		GasCoin:     "MNT",
		GasPrice:    1,
	}

	resHash, err := sdk.TxSellCoin(&slDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the SellAllCoin transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	slAllDt := m.TxSellAllCoinData{
		CoinToSell: "MNT",
		CoinToBuy:  "ABCDEF24",
		GasCoin:    "MNT",
		GasPrice:   1,
	}

	resHash, err := sdk.TxSellAllCoin(&slAllDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the BuyCoin transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	buyDt := m.TxBuyCoinData{
		CoinToSell: "ABCDEF23",
		CoinToBuy:  "MNT",
		ValueToBuy: 1,
		// Gas
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxBuyCoin(&buyDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the CreateCoin transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	creatDt := m.TxCreateCoinData{
		Name:                 "Test coin 24",
		Symbol:               "ABCDEF24",
		InitialAmount:        100,
		InitialReserve:       100,
		ConstantReserveRatio: 50,
		// Gas
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxCreateCoin(&creatDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the DeclareCandidacy transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	declDt := m.TxDeclareCandidacyData{
		PubKey:     "Mp2891198c692c351bc55ac60a03c82649fa920f7ad20bd290a0c4e774e916e9de", // "Mp....",
		Commission: 10,                                                                   // 10%
		Coin:       "MNT",
		Stake:      100,
		// Gas
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxDeclareCandidacy(&declDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)
}
Example
  • Sign the Delegate transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	delegDt := m.TxDelegateData{
		Coin:     "MNT",
		PubKey:   "Mp5c87d35a7adb055f54140ba03c0eed418ddc7c52ff7a63fc37a0e85611388610",
		Stake:    100,
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxDelegate(&delegDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the SetCandidate transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	sndDt := m.TxSetCandidateData{
		PubKey:   "Mp2891198c692c351bc55ac60a03c82649fa920f7ad20bd290a0c4e774e916e9de",
		Activate: true, //true-"on", false-"off"
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxSetCandidate(&sndDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Sign the Unbound transaction.
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	unbDt := m.TxUnbondData{
		PubKey:   "Mp5c87d35a7adb055f54140ba03c0eed418ddc7c52ff7a63fc37a0e85611388610",
		Coin:     "MNT",
		Value:    10,
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxUnbond(&unbDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}
Example
  • Transaction for editing existing candidate
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "your private key",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	edtCDt := m.TxEditCandidateData{
		PubKey:   "Mp09f3548f7f4fc38ad2d0d8f805ec2cc1e35696012f95b8c6f2749e304a91efa2",
		RewardAddress: "Mx7a86fb0d770062decdca3dc5fed15800d5a65000",
		OwnerAddress: "Mx58a1441883708813ba546345a0ed0ce765f1dad1",
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxEditCandidate(&edtCDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resHash)

}

Create Minter Check

  • Create check
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "...",
		ChainMainnet: false, // Main=>true, Test=>false
	}

	chDt := m.TxCreateCkeckData{
		Coin:     "MNT",
		Stake:    10,
		Password: "pswrd123",
		Nonce:    102,
	}

	resCheck, err := sdk.TxCreateCheck(&chDt)
	if err != nil {
		panic(err)
	}
	fmt.Println(resCheck)	
	// Mc.......
}
  • Redeem check
package main

import (
	"fmt"

	m "github.com/ValidatorCenter/minter-go-sdk"
)

func main() {
	sdk := m.SDK{
		MnAddress:     "https://minter-node-1.testnet.minter.network",
		AccPrivateKey: "...",
		ChainMainnet: false, // Main=>true, Test=>false
	}
	
	rchDt := m.TxRedeemCheckData{
		Check:    "Mc....",
		Password: "pswrd123",
		GasCoin:  "MNT",
		GasPrice: 1,
	}

	resHash, err := sdk.TxRedeemCheck(&rchDt)
	if err != nil {
		panic(err)
	}
	fmt.Println("HashTx:", resHash)
}