kaspa

package module
v0.0.0-...-be50d8c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 19 Imported by: 0

README

kaspa-sdk

Kaspa SDK is used to interact with the Kaspa blockchain, it contains various functions can be used to web3 wallet.

Installation

go get

To obtain the latest version, simply require the project using :

go get -u github.com/okx/go-wallet-sdk/coins/kaspa

Usage

New Address
	privateKeyHex := "559376194bb4c9a9dfb33fde4a2ab15daa8a899a3f43dee787046f57d5f7b10a"
	address, err := NewAddressWithNetParams(privateKeyHex, dagconfig.DevnetParams)
	if err != nil {
		// todo
	}
Transfer
	var txInputs []*TxInput
	txInputs = append(txInputs, &TxInput{
		TxId:       "120c5410cc4512f29da50a8befc67c1cfbf7bb4f594ef91c14741150d8dadd24",
		Index:      0,
		Address:    "kaspa:qrcnkrtrjptghtrntvyqkqafj06f9tamn0pnqvelmt2vmz68yp4gqj5lnal2h",
		Amount:     "900000",
		PrivateKey: "b827bb46d921bde498a535999d7554071045f02e4fdfdebb10b08583f1c6afbe",
	})
	txData := &TxData{
		TxInputs:      txInputs,
		ToAddress:     "kaspa:qqvxjssnw024e93vykhzd8d7t6dua2sx8ak4mj7xm8s9370yevxcv0jgl2xfj", // 443642da97444e52af9eb35e3d32d6270f47d255854b63299b29f21c1ded4c7c
		Amount:        "100000",
		Fee:           "10000",
		ChangeAddress: "kaspa:qrcnkrtrjptghtrntvyqkqafj06f9tamn0pnqvelmt2vmz68yp4gqj5lnal2h",
		MinOutput:     "546",
	}

	signedTx, err := Transfer(txData)
	if err != nil {
		// todo
	}

License

Most packages or folder are MIT licensed, see package or folder for the respective license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAddress

func NewAddress(prvKeyHex string) (string, error)

func NewAddressWithNetParams

func NewAddressWithNetParams(prvKeyHex string, params dagconfig.Params) (string, error)

func PrvKeyToPubKey

func PrvKeyToPubKey(prvKeyHex string) (string, error)

func SignMessage

func SignMessage(message string, privateKey []byte) (string, error)

func StrToUint64

func StrToUint64(s string) uint64

func Transfer

func Transfer(txData *TxData) (string, error)

func TransferWithNetParams

func TransferWithNetParams(txData *TxData, params dagconfig.Params) (string, error)

func ValidateAddress

func ValidateAddress(address string) bool

func ValidateAddressWithNetParams

func ValidateAddressWithNetParams(address string, params dagconfig.Params) bool

Types

type Outpoint

type Outpoint struct {
	TransactionId string `json:"transactionId"`
	Index         uint32 `json:"index"`
}

type ScriptPublicKey

type ScriptPublicKey struct {
	Version         uint32 `json:"version"`
	ScriptPublicKey string `json:"scriptPublicKey"`
}

type Transaction

type Transaction struct {
	Version      uint32               `json:"version"`
	Inputs       []*TransactionInput  `json:"inputs"`
	Outputs      []*TransactionOutput `json:"outputs"`
	LockTime     uint64               `json:"lockTime"`
	SubnetworkId string               `json:"subnetworkId"`
}

type TransactionInput

type TransactionInput struct {
	PreviousOutpoint *Outpoint `json:"previousOutpoint"`
	SignatureScript  string    `json:"signatureScript"`
	Sequence         uint64    `json:"sequence"`
	SigOpCount       uint32    `json:"sigOpCount"`
}

type TransactionMessage

type TransactionMessage struct {
	Transaction *Transaction `json:"transaction"`
	AllowOrphan bool         `json:"allowOrphan"`
}

type TransactionOutput

type TransactionOutput struct {
	Amount          uint64           `json:"amount"`
	ScriptPublicKey *ScriptPublicKey `json:"scriptPublicKey"`
}

type TransactionResult

type TransactionResult struct {
	Tx   string `json:"tx"`
	TxId string `json:"txId"`
}

type TxData

type TxData struct {
	TxInputs      []*TxInput `json:"txInputs"`
	ToAddress     string     `json:"toAddress"`
	Amount        string     `json:"amount"`
	Fee           string     `json:"fee"`
	ChangeAddress string     `json:"changeAddress"`
	MinOutput     string     `json:"minOutput"`
}

type TxInput

type TxInput struct {
	TxId       string `json:"txId"`
	Index      uint32 `json:"index"`
	Address    string `json:"address"`
	Amount     string `json:"amount"`
	PrivateKey string `json:"privateKey"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL