README

Elrond SDK for GO

Elrond SDK for GO

Dependencies

github.com/btcsuite/btcutil/bech32
github.com/tyler-smith/go-bip39
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bech32ToPubkey

func Bech32ToPubkey(address string) ([]byte, error)

Bech32ToPubkey converts an Elrond bech32 address to a pubkey

func GenerateNewMnemonic

func GenerateNewMnemonic() (string, error)

GenerateNewMnemonic generates a new set of 24 words to be used as seed phrase

func GetAddressFromPrivateKey

func GetAddressFromPrivateKey(privateKeyBytes []byte) (string, error)

GetAddressFromPrivateKey generates the bech32 address from a private key

func GetAddressShard

func GetAddressShard(address string, numShardsWithoutMeta uint32) (uint32, error)

GetAddressShard computes the shard of an address

func GetPrivateKeyFromMnemonic

func GetPrivateKeyFromMnemonic(mnemonic string, account, addressIndex uint8) []byte

GetPrivateKeyFromMnemonic generates a private key based on mnemonic, account and address index

func GetPubkeyShard

func GetPubkeyShard(pubkey []byte, numShardsWithoutMeta uint32) (uint32, error)

GetPubkeyShard computes the shard of a public key

func IsValidBech32Address

func IsValidBech32Address(address string) bool

IsValidBech32Address returns true if the provided parameter is a valid Elrond bech32 address and false otherwise

func IsValidPubkey

func IsValidPubkey(strPubkey string) bool

IsValidPubkey returns true if the provided parameter is a valid pubkey and false otherwise

func LoadPrivateKeyFromPemFile

func LoadPrivateKeyFromPemFile(filename string) ([]byte, error)

LoadPrivateKeyFromPemFile loads a private key from a .pem file

func PubkeyToBech32

func PubkeyToBech32(pubkey []byte) (string, error)

PubkeyToBech32 converts a pubkey to an Elrond bech32 address

func SavePrivateKeyToPemFile

func SavePrivateKeyToPemFile(privateKey []byte, filename string) error

SavePrivateKeyToPemFile saves the private key in a .pem file

func SignTransaction

func SignTransaction(tx *Transaction, privateKey []byte) error

SignTransaction signs a transaction with the provided private key

Types

type Account

type Account struct {
	Address  string `json:"address"`
	Nonce    uint64 `json:"nonce"`
	Balance  string `json:"balance"`
	Code     string `json:"code"`
	CodeHash []byte `json:"codeHash"`
	RootHash []byte `json:"rootHash"`
}

Account holds an Account's informations

func (*Account) GetBalance

func (a *Account) GetBalance(decimals int) (float64, error)

GetBalance computes the float representation of the balance, based on the provided number of decimals

type AccountResponse

type AccountResponse struct {
	Data struct {
		Account *Account `json:"account"`
	} `json:"data"`
	Error string `json:"error"`
	Code  string `json:"code"`
}

AccountResponse holds the account endpoint response

type ElrondProxy

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

ElrondProxy implements basic functions for interacting with an Elrond Proxy

func NewElrondProxy

func NewElrondProxy(url string) *ElrondProxy

NewElrondProxy initializes and returns an ElrondProxy object

func (*ElrondProxy) GetAccount

func (ep *ElrondProxy) GetAccount(address string) (*Account, error)

GetAccount retrieves an account info from the network (nonce, balance)

func (*ElrondProxy) GetHyperblockByHash

func (ep *ElrondProxy) GetHyperblockByHash(hash string) (*Hyperblock, error)

GetHyperblockByHash retrieves a hyperblock's info by hash from the network

func (*ElrondProxy) GetHyperblockByNonce

func (ep *ElrondProxy) GetHyperblockByNonce(nonce uint64) (*Hyperblock, error)

GetHyperblockByNonce retrieves a hyperblock's info by nonce from the network

func (*ElrondProxy) GetLatestHyperblockNonce

func (ep *ElrondProxy) GetLatestHyperblockNonce() (uint64, error)

GetLatestHyperblockNonce retrieves the latest hyperblock (metachain) nonce from the network

func (*ElrondProxy) GetNetworkConfig

func (ep *ElrondProxy) GetNetworkConfig() (*NetworkConfig, error)

GetNetworkConfig retrieves the network configuration from the proxy

func (*ElrondProxy) GetTransactionInfo

func (ep *ElrondProxy) GetTransactionInfo(hash string) (*TransactionInfo, error)

GetTransactionInfo retrieves a transaction's details from the network

func (*ElrondProxy) GetTransactionStatus

func (ep *ElrondProxy) GetTransactionStatus(hash string) (string, error)

GetTransactionStatus retrieves a transaction's status from the network

func (*ElrondProxy) SendTransaction

func (ep *ElrondProxy) SendTransaction(tx *Transaction) (string, error)

SendTransaction broadcasts a transaction to the network and returns the txhash if successful

type Hyperblock

type Hyperblock struct {
	Nonce         uint64 `json:"nonce"`
	Round         uint64 `json:"round"`
	Hash          string `json:"hash"`
	PrevBlockHash string `json:"prevBlockHash"`
	Epoch         uint64 `json:"epoch"`
	NumTxs        uint64 `json:"numTxs"`
	ShardBlocks   []struct {
		Hash  string `json:"hash"`
		Nonce uint64 `json:"nonce"`
		Shard uint32 `json:"shard"`
	} `json:"shardBlocks"`
	Transactions []TransactionOnNetwork
}

Hyperblock holds a hyperblock's details

type HyperblockResponse

type HyperblockResponse struct {
	Data struct {
		Hyperblock Hyperblock `json:"hyperblock"`
	}
	Error string `json:"error"`
	Code  string `json:"code"`
}

HyperblockResponse holds a hyperblock info response from the network

type NetworkConfig

type NetworkConfig struct {
	ChainID                  string `json:"erd_chain_id"`
	Denomination             int    `json:"erd_denomination"`
	GasPerDataByte           uint64 `json:"erd_gas_per_data_byte"`
	LatestTagSoftwareVersion string `json:"erd_latest_tag_software_version"`
	MetaConsensusGroup       uint64 `json:"erd_meta_consensus_group"`
	MinGasLimit              uint64 `json:"erd_min_gas_limit"`
	MinGasPrice              uint64 `json:"erd_min_gas_price"`
	MinTransactionVersion    uint32 `json:"erd_min_transaction_version"`
	NumMetachainNodes        uint64 `json:"erd_num_metachain_nodes"`
	NumNodesInShard          uint64 `json:"erd_num_nodes_in_shard"`
	NumShardsWithoutMeta     uint32 `json:"erd_num_shards_without_meta"`
	RoundDuration            int64  `json:"erd_round_duration"`
	ShardConsensusGroupSize  uint64 `json:"erd_shard_consensus_group_size"`
	StartTime                int64  `json:"erd_start_time"`
}

NetworkConfig holds the network configuration parameters

type NetworkConfigResponse

type NetworkConfigResponse struct {
	Data struct {
		Config *NetworkConfig `json:"config"`
	} `json:"data"`
	Error string `json:"error"`
	Code  string `json:"code"`
}

NetworkConfigResponse holds the network config endpoint response

type NetworkStatus

type NetworkStatus struct {
	CurrentRound               uint64 `json:"erd_current_round"`
	EpochNumber                uint64 `json:"erd_epoch_number"`
	Nonce                      uint64 `json:"erd_nonce"`
	NonceAtEpochStart          uint64 `json:"erd_nonce_at_epoch_start"`
	NoncesPassedInCurrentEpoch uint64 `json:"erd_nonces_passed_in_current_epoch"`
	RoundAtEpochStart          uint64 `json:"erd_round_at_epoch_start"`
	RoundsPassedInCurrentEpoch uint64 `json:"erd_rounds_passed_in_current_epoch"`
	RoundsPerEpoch             uint64 `json:"erd_rounds_per_epoch"`
}

NetworkStatus holds the network status details of a specified shard

type NetworkStatusResponse

type NetworkStatusResponse struct {
	Data struct {
		Status *NetworkStatus `json:"status"`
	} `json:"data"`
	Error string `json:"error"`
	Code  string `json:"code"`
}

NetworkStatusResponse holds the network status response (for a specified shard)

type SendTransactionResponse

type SendTransactionResponse struct {
	Data struct {
		TxHash string `json:"txHash"`
	} `json:"data"`
	Error string `json:"error"`
	Code  string `json:"code"`
}

SendTransactionResponse holds the response received from the network when broadcasting a transaction

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"`
	Signature string `json:"signature,omitempty"`
	ChainID   string `json:"chainID"`
	Version   uint32 `json:"version"`
}

Transaction holds the fields of a transaction to be broadcasted to the network

type TransactionInfo

type TransactionInfo struct {
	Data struct {
		Transaction TransactionOnNetwork `json:"transaction"`
	} `json:"data"`
	Error string `json:"error"`
	Code  string `json:"code"`
}

TransactionInfo holds a transaction info response from the network

type TransactionOnNetwork

type TransactionOnNetwork struct {
	Type             string `json:"type"`
	Hash             string `json:"hash"`
	Nonce            uint64 `json:"nonce"`
	Value            string `json:"value"`
	Receiver         string `json:"receiver"`
	Sender           string `json:"sender"`
	GasPrice         uint64 `json:"gasPrice"`
	GasLimit         uint64 `json:"gasLimit"`
	Data             []byte `json:"data"`
	Signature        string `json:"signature"`
	SourceShard      uint32 `json:"sourceShard"`
	DestinationShard uint32 `json:"destinationShard"`
	MiniblockType    string `json:"miniblockType"`
	MiniblockHash    string `json:"miniblockHash"`
	Status           string `json:"status"`
	HyperblockNonce  uint64 `json:"hyperblockNonce"`
	HyperblockHash   string `json:"hyperblockHash"`
}

TransactionOnNetwork holds a transaction's info entry in a hyperblock

type TransactionStatus

type TransactionStatus struct {
	Data struct {
		Status string `json:"status"`
	} `json:"data"`
	Error string `json:"error"`
	Code  string `json:"code"`
}

TransactionStatus holds a transaction's status response from the network