near

package module
v0.0.0-...-61460eb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 8 Imported by: 0

README

near-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/near

Usage

New Address
	addr, _, err := NewAccount()
	if err != nil {
		// todo
	}
Transfer
	privateKey := "b9ec4d26ab5bec8df4314a9e3b8fc3f9c96d410b4cd13caa675018dcfc7916cceefbba85caaa14cb87b83314d5b86895f2d4b7633e29012e65bfb037c885c804"
	val := 0.222
	to := "ggasii.testnet"
	blockHash := "D7CPxgTXyRKYTSYuwAiRwDJH5RdHz7DwPt4EViptAW4L"
	nonce := int64(1)
	addr, err := PrivateKeyToAddr(privateKey)
    if err != nil {
		// todo
	}
	publicKeyHex, err := PrivateKeyToPublicKeyHex(privateKey)
    if err != nil {
		// todo
	}
	tx, err := CreateTransaction(addr, to, publicKeyHex, blockHash, nonce)
    if err != nil {
		// todo
	}
	amount := decimal.NewFromFloat(val).Shift(24)
	ta, err := serialize.CreateTransfer(amount.String())
    if err != nil {
		// todo
	}
	tx.SetAction(ta)
	txData, err := tx.Serialize()
    if err != nil {
		// todo
	}
	txBase58 := base58.Encode(txData)
	sig, err := SignTransaction(txBase58, privateKey)
    if err != nil {
		// todo
	}
	stx, err := CreateSignedTransaction(tx, sig)
Transfer Token
	privateKey := "b9ec4d26ab5bec8df4314a9e3b8fc3f9c96d410b4cd13caa675018dcfc7916cceefbba85caaa14cb87b83314d5b86895f2d4b7633e29012e65bfb037c885c804"
	val := 0.222
	to := "ft.examples.testnet"
	blockHash := "D7CPxgTXyRKYTSYuwAiRwDJH5RdHz7DwPt4EViptAW4L"
	nonce := int64(1)
	argsStr := `{"account_id": "serhii.testnet"}`
	gas := big.NewInt(1)
	addr := "ggasii.testnet"
	publicKeyHex, err := PrivateKeyToPublicKeyHex(privateKey)
	require.NoError(t, err)
	tx, err := CreateTransaction(addr, to, publicKeyHex, blockHash, nonce)
	amount := decimal.NewFromFloat(val).Shift(24).BigInt()
	ta, err := serialize.CreateFunctionCall("storage_balance_of", []byte(argsStr), gas, amount)
	tx.SetAction(ta)
	txData, err := tx.Serialize()
	txHash := base58.Encode(txData)
	sig, err := SignTransaction(txHash, privateKey)
	stx, err := CreateSignedTransaction(tx, sig)
	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 NewAccount

func NewAccount() (address, seedHex string, err error)

func PrivateKeyToAddr

func PrivateKeyToAddr(privateKey string) (string, error)

func PrivateKeyToPublicKeyHex

func PrivateKeyToPublicKeyHex(privateKey string) (string, error)

func PublicKeyToAddress

func PublicKeyToAddress(publicKey string) (string, error)

func SignTransaction

func SignTransaction(txBase58 string, privateKey string) (string, error)

func ValidateAddress

func ValidateAddress(addr string) bool

ValidateAddress NOTE:Address is not account id.

Types

type ActionTransfer

type ActionTransfer struct {
	Transfer Transfer `json:"transfer"`
}

type SignatureData

type SignatureData struct {
	V *big.Int
	R *big.Int
	S *big.Int

	ByteV byte
	ByteR []byte
	ByteS []byte
}

type SignatureTransaction

type SignatureTransaction struct {
	Sig serialize.Signature
	Tx  *Transaction
}

func CreateSignedTransaction

func CreateSignedTransaction(tx *Transaction, sig string) (*SignatureTransaction, error)

func (*SignatureTransaction) Serialize

func (stx *SignatureTransaction) Serialize() ([]byte, error)

type Transaction

type Transaction struct {
	SignerId   serialize.String
	PublicKey  serialize.PublicKey
	Nonce      serialize.U64
	ReceiverId serialize.String
	BlockHash  serialize.BlockHash
	Actions    []serialize.IAction
}

func CreateTransaction

func CreateTransaction(from, to, publicKeyHex, blockHash string, nonce int64) (*Transaction, error)

func (*Transaction) GetSigningHash

func (tx *Transaction) GetSigningHash() (string, error)

func (*Transaction) Serialize

func (tx *Transaction) Serialize() ([]byte, error)

func (*Transaction) SetAction

func (tx *Transaction) SetAction(action ...serialize.IAction)

type Transfer

type Transfer struct {
	Deposit string `json:"deposit"` //amount
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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