polkadot

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

polkdot-sdk

Polkdot SDK is used to interact with the Polkdot 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/polkdot

Usage

New Address
	priKey, _ := hex.DecodeString("45d3bd794c5bc6ed91ae41c93c0baed679935703dfac72c48d27f8321b8d3a40")
	p := ed25519.NewKeyFromSeed(priKey)
	publicKey := p.Public().(ed25519.PublicKey)
	address, _ := PubKeyToAddress(publicKey, PolkadotPrefix)
Transfer
	tx := TxStruct{
		From:         "1GycBnSYfhVWN8yRxmLxJ6CXyyZEHgVJyiF8MWZDsKTLfhs",
		To:           "1GycBnSYfhVWN8yRxmLxJ6CXyyZEHgVJyiF8MWZDsKTLfhs",
		Amount:       10000000000,
		Nonce:        18,
		Tip:          0,
		BlockHeight:  10672081,
		BlockHash:    "0x569e9705bdcd3cf15edb1378433148d437f585a21ad0e2691f0d8c0083021580",
		GenesisHash:  "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3",
		SpecVersion:  9220,
		TxVersion:    12,
		ModuleMethod: "0500",
		Version:      "84",
	}

	signed, err := SignTx(tx, Transfer, "45d3bd794c5bc6ed91ae41c93c0baed679935703dfac72c48d27f8321b8d3a40")
	if err != nil {
		// todo
	}

License

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

Documentation

Index

Constants

View Source
const (
	Transfer    = 1 // balances-transfer  balances-transfer_keep_alive
	TransferAll = 2 //  balances-transfer_all
)

Variables

View Source
var (
	SubstratePrefix  = []byte{0x2a}
	PolkadotPrefix   = []byte{0x00}
	KsmPrefix        = []byte{0x02}
	DarwiniaPrefix   = []byte{0x12}
	EdgewarePrefix   = []byte{0x07}
	CentrifugePrefix = []byte{0x24}
	PlasmPrefix      = []byte{0x05}
	StafiPrefix      = []byte{0x14}
	KulupuPrefix     = []byte{0x10}
	BifrostPrefix    = []byte{0x06}
	KaruraPrefix     = []byte{0x08}
	ReynoldsPrefix   = []byte{0x09}
	AcalaPrefix      = []byte{0x0a}
	LaminarPrefix    = []byte{0x0b}
	PolymathPrefix   = []byte{0x0c}
	RobonomicsPrefix = []byte{0x20}
	ChainxPrefix     = []byte{0x2c}
	SSPrefix         = []byte{0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45}
)

Functions

func AddressToPublicKey

func AddressToPublicKey(address string) (string, error)

func BalanceTransfer

func BalanceTransfer(method, to string, amount uint64) ([]byte, error)

BalanceTransfer balances-transfer_keep_alive

func BalanceTransferAll

func BalanceTransferAll(method, to, keepAlive string) ([]byte, error)

BalanceTransferAll false: keepAlive 00

func BytesToCompactBytes

func BytesToCompactBytes(bytes []byte) (res []byte)

func CompactLength

func CompactLength(data uint32) int

func Encode

func Encode(data uint64) string

func ExtendLEBytes

func ExtendLEBytes(input []byte, length int) []byte

func GetEra

func GetEra(height uint64, calPeriod uint64) []byte

func PubKeyToAddress

func PubKeyToAddress(publicKey []byte, prefix []byte) (address string, err error)

func SignTx

func SignTx(tx TxStruct, txType int32, privateKey string) (string, error)

func SignTx2

func SignTx2(tx TxStruct2, signature []byte) (string, error)

func ValidateAddress

func ValidateAddress(addr string) bool

Types

type TxStruct

type TxStruct struct {
	ModuleMethod string `json:"module_method"`
	Version      string `json:"version"`
	From         string `json:"from"`
	To           string `json:"to"`
	Amount       uint64 `json:"amount"`
	Nonce        uint64 `json:"nonce"`
	Tip          uint64 `json:"tip"`
	BlockHeight  uint64 `json:"block_height"`
	BlockHash    string `json:"block_hash"`
	GenesisHash  string `json:"genesis_hash"`
	SpecVersion  uint32 `json:"spec_version"`
	TxVersion    uint32 `json:"tx_version"`
	KeepAlive    string `json:"keep_alive"`
	EraHeight    uint64 `json:"era_height"`
}

type TxStruct2

type TxStruct2 struct {
	ModuleMethod string `json:"module_method"`
	Version      string `json:"version"`
	From         string `json:"from"`
	To           string `json:"to"`
	Amount       uint64 `json:"amount"`
	Nonce        uint64 `json:"nonce"`
	Tip          uint64 `json:"tip"`
	BlockHash    string `json:"block_hash"`
	GenesisHash  string `json:"genesis_hash"`
	SpecVersion  string `json:"spec_version"`
	TxVersion    string `json:"tx_version"`
	Era          string `json:"era"`
}

type UnSignedTx

type UnSignedTx struct {
	Method      []byte
	Era         []byte
	Nonce       []byte
	Tip         []byte
	SpecVersion []byte
	GenesisHash []byte
	BlockHash   []byte
	TxVersion   []byte
}

func UnSignedTxFromTxStruct

func UnSignedTxFromTxStruct(tx TxStruct, txType int32) (UnSignedTx, error)

func UnSignedTxFromTxStruct2

func UnSignedTxFromTxStruct2(tx TxStruct2) (UnSignedTx, error)

func (*UnSignedTx) ToBytesString

func (t *UnSignedTx) ToBytesString() string

Jump to

Keyboard shortcuts

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