elrond

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

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 11 Imported by: 0

README

elrond-sdk

Elrond SDK is used to interact with the Elrond 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/xiaohuasheng0x1/blockchains/coins/elrond

Usage

address
	// address
    pk, _ := hex.DecodeString("27d57eb22fc218b83e9ea2da55746d9318ba6b89cfa31b797e7296bf8a66e4f1")
    address, err := AddressFromSeed(hex.EncodeToString(pk))
	if err != nil {
		// todo
		fmt.Println(err)
	}

transfer
	// transfer
	args := ArgCreateTransaction{
		Nonce:    3,
		Value:    "10000000000000000", // decimal 18
		RcvAddr:  toAddress,
		GasPrice: 1000000000,
		GasLimit: 50000,
		ChainID:  "T",
		Version:  2,
		Options:  1,
	}
    signedTx, err := Transfer(args, pk)
	if err != nil {
		// todo
		fmt.Println(err)
	}
	fmt.Println(data)

License

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

Documentation

Index

Constants

View Source
const (
	HRP = "erd"
)

Variables

This section is empty.

Functions

func AddressFromSeed

func AddressFromSeed(seed string) (string, error)

func GetNewAddressByPub

func GetNewAddressByPub(pubkey string) (string, error)

func NewAddress

func NewAddress(privateKey string) (string, error)

func NewTxDataBuilder

func NewTxDataBuilder() *txDataBuilder

NewTxDataBuilder creates a new transaction data builder

func SignedTx

func SignedTx(arg ArgCreateTransaction, sender string, signature string) string

func Transfer

func Transfer(args ArgCreateTransaction, privateKeyHex string) (string, error)

func UnsignedTx

func UnsignedTx(arg ArgCreateTransaction, sndAddr string, signature string) (string, error)

func ValidateAddress

func ValidateAddress(address string) bool

Types

type ArgCreateTransaction

type ArgCreateTransaction struct {
	Nonce    uint64
	Value    string
	RcvAddr  string
	GasPrice uint64
	GasLimit uint64
	// Arbitrary information about the transaction, base64-encoded.
	Data []byte
	// The chain identifier.
	ChainID string
	Version uint32
	Options uint32
}

ArgCreateTransaction will hold the transaction fields

type Transaction

type Transaction struct {
	Nonce    uint64 `json:"nonce"`
	Value    string `json:"value"`
	RcvAddr  string `json:"receiver"`
	SndAddr  string `json:"sender"`
	GasPrice uint64 `json:"gasPrice,omitempty"`
	GasLimit uint64 `json:"gasLimit,omitempty"`
	Data     []byte `json:"data,omitempty"`
	ChainID  string `json:"chainID"`
	Version  uint32 `json:"version"`
	Options  uint32 `json:"options,omitempty"`
	// The digital signature consisting of 128 hex-characters (thus 64 bytes in a raw representation)
	Signature string `json:"signature,omitempty"`
}

type TxBuilder

type TxBuilder struct {
	// contains filtered or unexported fields
}

func NewTxBuilder

func NewTxBuilder(key *ed25519.PrivateKey) *TxBuilder

NewTxBuilder will create a new transaction builder able to build and correctly sign a transaction

type TxDataBuilder

type TxDataBuilder interface {
	Function(function string) TxDataBuilder

	ArgHexString(hexed string) TxDataBuilder
	ArgAddress(address string) TxDataBuilder
	ArgBigInt(value *big.Int) TxDataBuilder
	ArgInt64(value int64) TxDataBuilder
	ArgBytes(bytes []byte) TxDataBuilder

	ToDataString() (string, error)
	ToDataBytes() ([]byte, error)

	IsInterfaceNil() bool
}

TxDataBuilder defines the behavior of a transaction data builder

Jump to

Keyboard shortcuts

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