All Projects β†’ MinterTeam β†’ minter-go-sdk

MinterTeam / minter-go-sdk

Licence: MIT license
Minter Blockchain Golang SDK, πŸ’³ wallet, 🧾 transactions, gRPC and HTTP clients 🌐 https://t.me/MinterGoSDK

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to minter-go-sdk

SimpleCoin
A simple cryptocurrency application for educational purposes only.
Stars: ✭ 13 (+8.33%)
Mutual labels:  transaction, wallet
eth.rb
a straightforward library to build, sign, and broadcast ethereum transactions anywhere you can run ruby.
Stars: ✭ 111 (+825%)
Mutual labels:  transaction, rlp
rlp
Recursive Length Prefix Encoding in PHP.
Stars: ✭ 25 (+108.33%)
Mutual labels:  transaction, rlp
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions on Ethereum network.
Stars: ✭ 462 (+3750%)
Mutual labels:  transaction, wallet
Blockchain Wallet
εŒΊε—ι“Ύι’±εŒ…ζŠ€ζœ―ζŒ‡ε—
Stars: ✭ 205 (+1608.33%)
Mutual labels:  transaction, wallet
Coinbin
Javascript Bitcoin Wallet. Supports Multisig, Stealth, HD, SegWit, Bech32, Time Locked Addresses, RBF and more!
Stars: ✭ 694 (+5683.33%)
Mutual labels:  transaction, wallet
Web Wallet
Stars: ✭ 261 (+2075%)
Mutual labels:  transaction, wallet
simple-mpesa
A simple example of how MPESA works. Works with all 3 types of customers i.e. Agents, Merchants and Subscribers. Allows you to configure a tariff and apply it to transactions. The project follows DDD principles.
Stars: ✭ 31 (+158.33%)
Mutual labels:  transaction, wallet
arweave-python-client
This client allows you to integrate your python apps with the Arweave network allowing you to perform wallet operations and transactions
Stars: ✭ 87 (+625%)
Mutual labels:  transaction, wallet
yara-parser
Tools for parsing rulesets using the exact grammar as YARA. Written in Go.
Stars: ✭ 69 (+475%)
Mutual labels:  signatures
openapi-generator-go
An opinionated OpenAPI v3 code generator for Go. Use this to generate API models and router scaffolding.
Stars: ✭ 42 (+250%)
Mutual labels:  openapi
fastapi-tortoise
The template for building scalable web APIs based on FastAPI, Tortoise ORM and other.
Stars: ✭ 95 (+691.67%)
Mutual labels:  openapi
whook
Build strong and efficient REST web services.
Stars: ✭ 18 (+50%)
Mutual labels:  openapi
data exchange
Data exchange Client including wallet
Stars: ✭ 36 (+200%)
Mutual labels:  wallet
laravel-reset-transaction
distributed transaction for call remote api service
Stars: ✭ 40 (+233.33%)
Mutual labels:  transaction
speckle-browser-extension
Universal browser extension for Web 3 and the Polkadot ecosystem
Stars: ✭ 28 (+133.33%)
Mutual labels:  wallet
go-fastapi
Create an API and get Swagger definition for free
Stars: ✭ 76 (+533.33%)
Mutual labels:  openapi
Multy-android
Mobile multy-blockchain wallet client.
Stars: ✭ 17 (+41.67%)
Mutual labels:  wallet
ssc-restapi-client
Communicate with Fortify Software Security Center through REST API in java, a swagger generated client
Stars: ✭ 13 (+8.33%)
Mutual labels:  openapi
connexion-example-redis-kubernetes
Connexion Example REST Service with Redis Store
Stars: ✭ 24 (+100%)
Mutual labels:  openapi

Minter Logo

go.dev reference

Overview

This is a pure Go SDK for working with Minter blockchain

Table of contents

Installing

go get github.com/MinterTeam/minter-go-sdk/v2@latest

Minter API

Minter blockchain nodes have built-in API with grpc and http + websocket interfaces. This package will help you with forming requests, parsing responses, as well as when working with other API entities.

Using API v2

Package http_client package implements the API v2 methods usage interface.

go.dev reference

package http_client_test

import (
	"context"
	"github.com/MinterTeam/minter-go-sdk/v2/api"
	"github.com/MinterTeam/minter-go-sdk/v2/api/http_client"
	"github.com/MinterTeam/minter-go-sdk/v2/api/http_client/models"
	"github.com/MinterTeam/minter-go-sdk/v2/transaction"
	"github.com/MinterTeam/minter-go-sdk/v2/wallet"
	"io"
	"math/big"
	"time"
)

func main() {
	client, _ := http_client.New("http://localhost:8843/v2")
	coinID, _ := client.CoinID("SYMBOL")
	w, _ := wallet.Create("1 2 3 4 5 6 7 8 9 10 11 12", "")
	nonce, _ := client.Nonce(w.Address)
	data := transaction.NewSendData().SetCoin(coinID).SetValue(transaction.BipToPip(big.NewInt(1))).MustSetTo(w.Address)
	transactionsBuilder := transaction.NewBuilder(transaction.TestNetChainID)
	tx, _ := transactionsBuilder.NewTransaction(data)
	sign, _ := tx.SetNonce(nonce).Sign(w.PrivateKey)
	encode, _ := sign.Encode()
	hash, _ := sign.Hash()

	subscribeClient, _ := client.Subscribe(api.QueryHash(hash))
	defer subscribeClient.CloseSend()

	res, err := client.SendTransaction(encode)
	if err != nil {
		_, _, _ = client.ErrorBody(err)
	}
	if res.Code != 0 {
		panic(res.Log)
	}

	{
		recv, err := subscribeClient.Recv()
		if err == io.EOF {
			return
		}
		if err == context.Canceled || err == context.DeadlineExceeded {
			return
		}
		if err != nil {
			panic(err)
		}

		marshal, _ := client.Marshal(recv)
		findedTx, _ := api.SubscribeNewTxToTx(marshal)
		_, _ = findedTx.GetTransaction(), findedTx.Data().(*transaction.SendData)
	}
	// or
	{
		time.Sleep(5*time.Second)
		response, _ := client.Transaction(hash)
		_, _ = client.Marshal(response)
		sendData := new(models.SendData)
		_ = response.Data.UnmarshalTo(sendData)
		_, _ = client.Marshal(sendData)
	}
}

Using gRPC

Package grpc_client package implements the gRPC methods usage interface.

go.dev reference

package grpc_client_test

import (
	"github.com/MinterTeam/minter-go-sdk/v2/api"
	"github.com/MinterTeam/minter-go-sdk/v2/api/grpc_client"
	"github.com/MinterTeam/minter-go-sdk/v2/transaction"
	"github.com/MinterTeam/minter-go-sdk/v2/wallet"
	"github.com/MinterTeam/node-grpc-gateway/api_pb"
	grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"io"
	"math/big"
	"time"
)

func main() {
	client, _ := grpc_client.New("localhost:8842")
	coinID, _ := client.CoinID("SYMBOL")
	w, _ := wallet.Create("1 2 3 4 5 6 7 8 9 10 11 12", "")
	nonce, _ := client.Nonce(w.Address)
	data := transaction.NewSendData().SetCoin(coinID).SetValue(transaction.BipToPip(big.NewInt(1))).MustSetTo(w.Address)
	transactionsBuilder := transaction.NewBuilder(transaction.TestNetChainID)
	tx, _ := transactionsBuilder.NewTransaction(data)
	sign, _ := tx.SetNonce(nonce).Sign(w.PrivateKey)
	encode, _ := sign.Encode()
	hash, _ := sign.Hash()

	subscribeClient, _ := client.Subscribe(api.QueryHash(hash))
	defer subscribeClient.CloseSend()

	res, err := client.WithCallOption(
		grpc_retry.WithCodes(codes.FailedPrecondition),
		grpc_retry.WithBackoff(grpc_retry.BackoffLinear(1*time.Second)),
		grpc_retry.WithMax(4),
	).SendTransaction(encode)
	if err != nil {
		_, _, _ = client.ErrorBody(err)
	}
	if res.Code != 0 {
		panic(res.Log)
	}

	{
		recv, err := subscribeClient.Recv()
		if err == io.EOF {
			return
		}
		if code := status.Code(err); code != codes.OK {
			if code == codes.DeadlineExceeded || code == codes.Canceled {
				return
			}
			panic(err)
		}

		marshal, _ := client.Marshal(recv)
		findedTx, _ := api.SubscribeNewTxToTx(marshal)
		_, _ = findedTx.GetTransaction(), findedTx.Data().(*transaction.SendData)
	}
	// or
	{
		time.Sleep(5*time.Second)
		response, _ := client.Transaction(hash)
		_, _ = client.Marshal(response)
		sendData := new(api_pb.SendData)
		_ = response.Data.UnmarshalTo(sendData)
		_, _ = client.Marshal(sendData)
	}
}

Using Transactions

Package transaction is a guide and assistant in working with fields and types of transactions, creating signatures, encoding and decoding with RLP.

go.dev reference

Sign transaction

Returns a signed tx.

⚠️ After sending the transaction, to make sure that the transaction was successfully committed on the blockchain, you need to find the transaction by hash and make sure that the status code is 0.

Single signature
Example
tx, _ := transaction.NewBuilder(transaction.TestNetChainID).NewTransaction(
  transaction.NewSendData().
    SetCoin(0).
    SetValue(transaction.BipToPip(big.NewInt(1))).
    MustSetTo("Mx1b685a7c1e78726c48f619c497a07ed75fe00483"),
)

signedTransaction, _ := tx.SetNonce(1).Sign("07bc17abdcee8b971bb8723e36fe9d2523306d5ab2d683631693238e0f9df142")

encode, _ := signedTransaction.Encode()
Multi signatures
Example
tx, _ := transaction.NewBuilder(transaction.TestNetChainID).NewTransaction(
  transaction.NewSendData().
  SetCoin(0).
  SetValue(transaction.BipToPip(big.NewInt(1))).
  MustSetTo("Mx1b685a7c1e78726c48f619c497a07ed75fe00483")
)

signedTx, _ := tx.SetNonce(1).SetMultiSignatureType().Sign(
  multisigAddress,
  "ae089b32e4e0976ca6888cb1023148bd1a9f1cc28c5d442e52e586754ff48d63",
  "b0a65cd84d57189b70d80fe0b3d5fa3ea6e02fa48041314a587a1f8fdba703d7",
  "4c8dbfb3258f383adf656c2131e5ed77ec482a36125db71fb49d29e0528ff2ba",
)

encode, _ := signedTx.Encode()

You can transfer the transaction to the remaining addresses

signedTx1, _ := tx.Sign(msigAddress, privateKey1)
encode, _ := signedTx.Encode()
// transfer encode transaction
signedTx1, _ = transaction.Decode(encode)
// and continue its signature by the remaining participants
signedTx12, _ := signedTx1.Sign(msigAddress, privateKey2)
signedTx123, _ := signedTx12.Sign(msigAddress, privateKey3)
encode, _ := signedTx123.Encode()

You can collect all signatures in one place without revealing the private key

signedTx1, _ := tx.Clone().Sign(msigAddress, "ae089b32e4e0976ca6888cb1023148bd1a9f1cc28c5d442e52e586754ff48d63")
signedTx2, _ := tx.Clone().Sign(msigAddress, "b0a65cd84d57189b70d80fe0b3d5fa3ea6e02fa48041314a587a1f8fdba703d7")
signedTx3, _ := tx.Clone().Sign(msigAddress, "4c8dbfb3258f383adf656c2131e5ed77ec482a36125db71fb49d29e0528ff2ba")
simpleSignatureData1, _ := signedTx1.SingleSignatureData()
simpleSignatureData2, _ := signedTx2.SingleSignatureData()
simpleSignatureData3, _ := signedTx3.SingleSignatureData()
signedTransaction, _ := tx.Clone().Sign(msigAddress)
signedTx123, _ := signedTransaction.AddSignature(simpleSignatureData1, simpleSignatureData2, simpleSignatureData3)

encode, _ := signedTx123.Encode()

Minter Wallet

Package wallet is a guide and assistant in working with addresses, mnemonic and initial phrases, private and public keys.

go.dev reference

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].