Documentation ¶
Overview ¶
Package zillean is golang library for Zilliqa blockchain.
Example ¶
package main import ( "fmt" "math/big" ) const endpoint = "https://api.zilliqa.com" func main() { // generate a new account toZil := NewZillean(endpoint) toPrivKey := toZil.GeneratePrivateKey() toPubKey, _ := toZil.GetPublicKeyFromPrivateKey(toPrivKey) toAddress, _ := toZil.GetAddressFromPrivateKey(toPrivKey) fmt.Printf("private key: %s\n", toPrivKey) fmt.Printf("public key: %s\n", toPubKey) fmt.Printf("address: %s\n", toAddress) // use an existing account fromZil := NewZillean(endpoint) fromPrivKey := "AAFD338492962FAD674EE3BD6EBC57C8373B2C9BADBAC8806D890F1FE8C571DF" fromPubKey, _ := fromZil.GetPublicKeyFromPrivateKey(fromPrivKey) // create a transaction rawTx := RawTransaction{ Version: 0, Nonce: 1, To: toAddress, Amount: "1000000000000", PubKey: fromPubKey, GasPrice: big.NewInt(1000000000), GasLimit: 1, } signature, _ := fromZil.SignTransaction(rawTx, fromPrivKey) txID, _ := fromZil.RPC.CreateTransaction(rawTx, signature) fmt.Printf("txID: %s\n", txID) }
Output:
Index ¶
- type Balance
- type BlockchainInfo
- type DsBlock
- type ECSchnorr
- type ListedBlocks
- type RPC
- func (r *RPC) CreateTransaction(rawTx RawTransaction, signature string) (string, error)
- func (r *RPC) DSBlockListing(pageNumber int64) (*ListedBlocks, error)
- func (r *RPC) GetBalance(address string) (*Balance, error)
- func (r *RPC) GetBlockchainInfo() (*BlockchainInfo, error)
- func (r *RPC) GetContractAddressFromTransactionID(txHash string) (string, error)
- func (r *RPC) GetCurrentDSEpoch() (string, error)
- func (r *RPC) GetCurrentMiniEpoch() (string, error)
- func (r *RPC) GetDSBlockRate() (float64, error)
- func (r *RPC) GetDsBlock(blockNumber string) (*DsBlock, error)
- func (r *RPC) GetLatestDsBlock() (*DsBlock, error)
- func (r *RPC) GetLatestTxBlock() (*TxBlock, error)
- func (r *RPC) GetMinimumGasPrice() (string, error)
- func (r *RPC) GetNetworkID() (string, error)
- func (r *RPC) GetNumDSBlocks() (string, error)
- func (r *RPC) GetNumTransactions() (string, error)
- func (r *RPC) GetNumTxBlocks() (string, error)
- func (r *RPC) GetNumTxnsDSEpoch() (string, error)
- func (r *RPC) GetNumTxnsTxEpoch() (string, error)
- func (r *RPC) GetPrevDSDifficulty() (int64, error)
- func (r *RPC) GetPrevDifficulty() (int64, error)
- func (r *RPC) GetRecentTransactions() (*RecentTransactions, error)
- func (r *RPC) GetShardingStructure() (*ShardingStructure, error)
- func (r *RPC) GetSmartContractCode(contractAddress string) (string, error)
- func (r *RPC) GetSmartContractInit(contractAddress string) ([]SmartContractState, error)
- func (r *RPC) GetSmartContractState(contractAddress string) ([]SmartContractState, error)
- func (r *RPC) GetSmartContracts(address string) ([]SmartContract, error)
- func (r *RPC) GetTransaction(txHash string) (*Transaction, error)
- func (r *RPC) GetTransactionRate() (float64, error)
- func (r *RPC) GetTransactionsForTxBlock(blockNumber string) ([][]string, error)
- func (r *RPC) GetTxBlock(blockNumber string) (*TxBlock, error)
- func (r *RPC) GetTxBlockRate() (float64, error)
- func (r *RPC) TxBlockListing(pageNumber int64) (*ListedBlocks, error)
- type RawTransaction
- type RecentTransactions
- type ShardingStructure
- type SmartContract
- type SmartContractState
- type Transaction
- type TxBlock
- type Zillean
- func (z *Zillean) GeneratePrivateKey() string
- func (z *Zillean) GetAddressFromPrivateKey(privateKey string) (string, error)
- func (z *Zillean) GetAddressFromPublicKey(publicKey string) (string, error)
- func (z *Zillean) GetPublicKeyFromPrivateKey(privateKey string) (string, error)
- func (z *Zillean) IsAddress(address string) bool
- func (z *Zillean) IsPublicKey(publicKey string) bool
- func (z *Zillean) SignTransaction(rawTx RawTransaction, privateKey string) (string, error)
- func (z *Zillean) VerifyPrivateKey(privateKey string) (bool, error)
- func (z *Zillean) VerifySignature(r, s, publicKey, msg []byte) bool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockchainInfo ¶
type BlockchainInfo struct { CurrentDSEpoch string `json:"CurrentDSEpoch"` CurrentMiniEpoch string `json:"CurrentMiniEpoch"` DSBlockRate float64 `json:"DSBlockRate"` NumDSBlocks string `json:"NumDSBlocks"` NumPeers int64 `json:"NumPeers"` NumTransactions string `json:"NumTransactions"` NumTxBlocks string `json:"NumTxBlocks"` NumTxnsDSEpoch string `json:"NumTxnsDSEpoch"` NumTxnsTxEpoch int64 `json:"NumTxnsTxEpoch"` ShardingStructure ShardingStructure `json:"ShardingStructure"` TransactionRate int64 `json:"TransactionRate"` TxBlockRate float64 `json:"TxBlockRate"` }
BlockchainInfo describes the information about Zilliqa blockchain.
type DsBlock ¶
type DsBlock struct { Header struct { BlockNum string `json:"blockNum"` Difficulty int64 `json:"difficulty"` DifficultyDS int64 `json:"difficultyDS"` GasPrice string `json:"gasPrice"` LeaderPubKey string `json:"leaderPubKey"` PoWWinners []string `json:"powWinners"` Prevhash string `json:"prevhash"` Timestamp string `json:"timestamp"` } `json:"header"` Signature string `json:"signature"` }
DsBlock describes a DS-Block.
type ECSchnorr ¶
ECSchnorr represents a EC-Schnorr object.
See https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/TechGuidelines/TR03111/BSI-TR-03111_pdf.pdf?__blob=publicationFile&v=1 for more information about the EC-Schnorr signature implementation.
func (*ECSchnorr) GeneratePrivateKey ¶
GeneratePrivateKey generates a new private key for Schnorr signature.
func (*ECSchnorr) GetPublicKey ¶
GetPublicKey returns the public key of a corresponding private key.
type ListedBlocks ¶
type ListedBlocks struct { Data []struct { BlockNum int64 `json:"BlockNum"` Hash string `json:"Hash"` } `json:"data"` MaxPages int64 `json:"maxPages"` }
ListedBlocks contains the paginated list of Blocks. This can be used for both DS-Blocks and TX-Blocks.
type RPC ¶
type RPC struct {
// contains filtered or unexported fields
}
RPC represents a JSON-RPC API client object.
func (*RPC) CreateTransaction ¶
func (r *RPC) CreateTransaction(rawTx RawTransaction, signature string) (string, error)
CreateTransaction create a new Transaction. See https://github.com/Zilliqa/Zilliqa-JavaScript-Library/#createtransactionjson in javascript for an example of how to construct the transaction object.
func (*RPC) DSBlockListing ¶
func (r *RPC) DSBlockListing(pageNumber int64) (*ListedBlocks, error)
DSBlockListing returns a paginated list of Directory Service blocks. Pass in page number as parameter. Returns a maxPages variable that specifies the max number of pages. 1 - latest blocks, maxPages - oldest blocks.
func (*RPC) GetBalance ¶
GetBalance returns the balance and nonce of a given address.
func (*RPC) GetBlockchainInfo ¶
func (r *RPC) GetBlockchainInfo() (*BlockchainInfo, error)
GetBlockchainInfo returns statistics about the specified zilliqa node.
func (*RPC) GetContractAddressFromTransactionID ¶
GetContractAddressFromTransactionID returns a smart contract address of 20 bytes from a transaction ID, represented as a String .
func (*RPC) GetCurrentDSEpoch ¶
GetCurrentDSEpoch returns the number of DS epochs in the network so far represented as String.
func (*RPC) GetCurrentMiniEpoch ¶
GetCurrentMiniEpoch returns the number of TX epochs in the network so far represented as String.
func (*RPC) GetDSBlockRate ¶
GetDSBlockRate returns the current Directory Service blockrate per second.
func (*RPC) GetDsBlock ¶
GetDsBlock returns details of a Directory Service block by block number.
func (*RPC) GetLatestDsBlock ¶
GetLatestDsBlock returns details of the most recent Directory Service block.
func (*RPC) GetLatestTxBlock ¶
GetLatestTxBlock returns details of the most recent Transaction block.
func (*RPC) GetMinimumGasPrice ¶
GetMinimumGasPrice returns the minimum gas price of the last DS epoch represented as String. This is measured in the smallest price unit Qa (10^-12 Zil) in Zilliqa.
func (*RPC) GetNetworkID ¶
GetNetworkID returns the network ID of the specified zilliqa node.
func (*RPC) GetNumDSBlocks ¶
GetNumDSBlocks returns the number of Directory Service blocks in the network so far. This is represented as a String.
func (*RPC) GetNumTransactions ¶
GetNumTransactions returns the number of Transactions validated in the network so far. This is represented as a String.
func (*RPC) GetNumTxBlocks ¶
GetNumTxBlocks returns the number of Transaction blocks in the network so far, this is represented as String.
func (*RPC) GetNumTxnsDSEpoch ¶
GetNumTxnsDSEpoch returns the number of transactions in this Directory Service epoch, this is represented as String.
func (*RPC) GetNumTxnsTxEpoch ¶
GetNumTxnsTxEpoch returns the number of transactions in this Transaction epoch, this is represented as String.
func (*RPC) GetPrevDSDifficulty ¶
GetPrevDSDifficulty returns the minimum DS difficulty of the previous block, this is represented as an Number.
func (*RPC) GetPrevDifficulty ¶
GetPrevDifficulty returns the minimum shard difficulty of the previous block, this is represented as an Number.
func (*RPC) GetRecentTransactions ¶
func (r *RPC) GetRecentTransactions() (*RecentTransactions, error)
GetRecentTransactions returns the most recent transactions (upto 100) accepted by the specified zilliqa node.
func (*RPC) GetShardingStructure ¶
func (r *RPC) GetShardingStructure() (*ShardingStructure, error)
GetShardingStructure returns the current sharding structure of the network from the specified network's lookup node.
func (*RPC) GetSmartContractCode ¶
GetSmartContractCode returns the Scilla code of a smart contract address.
func (*RPC) GetSmartContractInit ¶
func (r *RPC) GetSmartContractInit(contractAddress string) ([]SmartContractState, error)
GetSmartContractInit returns the initialization parameters (immutable) of a given smart contract address.
func (*RPC) GetSmartContractState ¶
func (r *RPC) GetSmartContractState(contractAddress string) ([]SmartContractState, error)
GetSmartContractState returns the state variables (mutable) of a smart contract address.
func (*RPC) GetSmartContracts ¶
func (r *RPC) GetSmartContracts(address string) ([]SmartContract, error)
GetSmartContracts returns the list of smart contracts created by an address.
func (*RPC) GetTransaction ¶
func (r *RPC) GetTransaction(txHash string) (*Transaction, error)
GetTransaction returns details of a Transaction by its hash.
func (*RPC) GetTransactionRate ¶
GetTransactionRate returns the current Transaction rate of the network.
func (*RPC) GetTransactionsForTxBlock ¶
GetTransactionsForTxBlock returns the transactions included within a micro-block created by a specific shard.
func (*RPC) GetTxBlock ¶
GetTxBlock returns details of a Transaction block by block number.
func (*RPC) GetTxBlockRate ¶
GetTxBlockRate returns the current Transaction blockrate per second.
func (*RPC) TxBlockListing ¶
func (r *RPC) TxBlockListing(pageNumber int64) (*ListedBlocks, error)
TxBlockListing returns a paginated list of Transaction blocks. Pass in page number as parameter. Returns a maxPages variable that specifies the max number of pages. 1 - latest blocks, maxPages - oldest blocks.
type RawTransaction ¶
type RawTransaction struct { Version uint32 `json:"version"` Nonce uint64 `json:"nonce"` To string `json:"toAddr"` Amount string `json:"amount"` PubKey string `json:"pubKey"` GasPrice *big.Int `json:"gasPrice"` GasLimit uint64 `json:"gasLimit"` Code string `json:"code"` Data string `json:"data"` Signature string `json:"signature"` }
RawTransaction describes a raw transaction object, which can be used in creating a new transaction.
type RecentTransactions ¶
type RecentTransactions struct { TxnHashes []string `json:"TxnHashes"` Number int64 `json:"number"` }
RecentTransactions contains the most recent transactions (up to 100).
type ShardingStructure ¶
type ShardingStructure struct {
NumPeers []int64 `json:"NumPeers"`
}
ShardingStructure contains the number of peers in each shard.
type SmartContract ¶
type SmartContract struct { Address string `json:"address"` State []SmartContractState `json:"state"` }
SmartContract describes the smart contracts created by an address.
type SmartContractState ¶
type SmartContractState struct { Type string `json:"type"` Value string `json:"value"` Vname string `json:"vname"` }
SmartContractState describes the state of a smart contract.
type Transaction ¶
type Transaction struct { ID string `json:"ID"` Amount string `json:"amount"` GasLimit string `json:"gasLimit"` GasPrice string `json:"gasPrice"` Nonce string `json:"nonce"` Receipt struct { CumulativeGas string `json:"cumulative_gas"` EpochNum string `json:"epoch_num"` Success bool `json:"success"` } `json:"receipt"` SenderPubKey string `json:"senderPubKey"` Signature string `json:"signature"` ToAddr string `json:"toAddr"` Version string `json:"version"` }
Transaction describes a transaction object.
type TxBlock ¶
type TxBlock struct { Body struct { HeaderSign string `json:"HeaderSign"` MicroBlockInfos []struct { MicroBlockHash string `json:"MicroBlockHash"` MicroBlockShardID int64 `json:"MicroBlockShardId"` MicroBlockTxnRootHash string `json:"MicroBlockTxnRootHash"` } `json:"MicroBlockInfos"` } `json:"body"` Header struct { BlockNum string `json:"BlockNum"` DsBlockNum string `json:"DSBlockNum"` GasLimit string `json:"GasLimit"` GasUsed string `json:"GasUsed"` MbInfoHash string `json:"MbInfoHash"` MinerPubKey string `json:"MinerPubKey"` NumMicroBlocks int64 `json:"NumMicroBlocks"` NumTxns int64 `json:"NumTxns"` PrevBlockHash string `json:"PrevBlockHash"` Rewards string `json:"Rewards"` StateDeltaHash string `json:"StateDeltaHash"` StateRootHash string `json:"StateRootHash"` Timestamp string `json:"Timestamp"` TxnHash string `json:"TxnHash"` Version int64 `json:"version"` } `json:"header"` }
TxBlock describes a TX-Block.
type Zillean ¶
Zillean represents the zillean object.
func (*Zillean) GeneratePrivateKey ¶
GeneratePrivateKey returns string which represents a generated private key.
func (*Zillean) GetAddressFromPrivateKey ¶
GetAddressFromPrivateKey returns the address derived from a private key.
func (*Zillean) GetAddressFromPublicKey ¶
GetAddressFromPublicKey returns the address derived from a public key.
func (*Zillean) GetPublicKeyFromPrivateKey ¶
GetPublicKeyFromPrivateKey returns the public key derived from a private key.
func (*Zillean) IsPublicKey ¶
IsPublicKey checks whether a given string is a public key or not.
func (*Zillean) SignTransaction ¶
func (z *Zillean) SignTransaction(rawTx RawTransaction, privateKey string) (string, error)
SignTransaction returns the EC-Schnorr signature on a raw transaction.
func (*Zillean) VerifyPrivateKey ¶
VerifyPrivateKey verifies a EC-Schnorr private key.
func (*Zillean) VerifySignature ¶
VerifySignature verifies a signature on a message.