This is a Golang client library, used to communicate with the AElf API.
- Protobuff 3.7.1
- Go 1.13.7
- VsCode
Example.go is provided to show how to use AElfClient.
import ("github.com/AElfProject/aelf-sdk.go/client")
// get client instance
var aelf = client.AElfClient
{
Host: "http://127.0.0.1:8000",
Version: "1.0",
PrivateKey: "680afd630d82ae5c97942c4141d60b8a9fedfa5b2864fca84072c17ee1f72d9d",
}
height, err := aelf.GetBlockHeight()
func (a *AElfClient) GetBlockHeight() (float64, error);
func (a *AElfClient) GetBlockByHash(blockHash string, isTransactions bool) (BlockDto, error);
func (a *AElfClient) GetBlockByHeight(blockHeight int, isTransactions bool) (BlockDto, error);
func (a *AElfClient) GetChainStatus() (ChainStatusDto, error);
func (a *AElfClient) GetContractFileDescriptorSet(address string) ([]byte, error);
func (a *AElfClient) GetChainID() (int, error);
func (a *AElfClient) GetTaskQueueStatus() ([]TaskQueueInfoDto, error);
func (a *AElfClient) AddPeer(ipAddress string) (bool), error);
func (a *AElfClient) RemovePeer(address string) (bool, error);
func (a *AElfClient) GetPeers(withMetrics bool) ([]PeerDto, error);
func (a *AElfClient) GetNetworkInfo() (NetworkInfo, error);
func (a *AElfClient) GetTransactionPoolStatus() (TransactionPoolStatus, error);
func (a *AElfClient) GetTransactionResult(transactionID string) (TransactionResultDto, error);
func (a *AElfClient) GetTransactionResults(blockHash string, offset = 0, limit = 10) ([]TransactionResultDto, error);
func (a *AElfClient) GetMerklePathByTransactionID(transactionID string) (*dto.MerklePathDto, error);
func (a *AElfClient) ExecuteTransaction(rawTransaction string) (string, error);
func (a *AElfClient) ExecuteRawTransaction(input ExecuteRawTransactionDto) (map[string]interface{}, error);
func (a *AElfClient) SendTransaction(transaction string) (SendTransactionOutput, error);
func (a *AElfClient) CreateRawTransaction(input CreateRawTransactionInput) (CreateRawTransactionOutput, error);
func (a *AElfClient) SendRawTransaction(input SendRawTransactionInput) (SendRawTransactionOutput, error);
func (a *AElfClient) SendTransactions(rawTransactions string) ([]string, error);
func (a *AElfClient) IsConnected() bool;
func (a *AElfClient) GetFormattedAddress(address string) (string, error);
func (a *AElfClient) GetAddressFromPubKey(pubkey string) string;
func (a *AElfClient) GetAddressFromPrivateKey(privateKey string) string;
func (a *AElfClient) GetGenesisContractAddress() (string, error);
func (a *AElfClient) GetContractAddressByName(contractName []byte) (string, error);
func (a *AElfClient) GenerateKeyPairInfo() *model.KeyPairInfo;
func GetSignatureWithPrivateKey(privateKey string, txData []byte) (string, error)
This module contains tests for all services provided by AElfClient. You can learn how to properly use services provided by AElfClient here.
You need to firstly set necessary parameters to make sure tests can run successfully.
-
Set baseUrl to your target url.
Host: "http://127.0.0.1:8000"
-
Give a valid privateKey of a node.
PrivateKey: "680afd630d82ae5c97942c4141d60b8a9fedfa5b2864fca84072c17ee1f72d9d"
-
You can optionally run a test case by specifying the name of a test case.
cd test/ go test -v -run TestGetChainStatus
Default classes defined in the "protobuf/proto" are available in the directory named "protobuf/generated".
You can add new proto files and generate types by using the script ./protobuff.sh
.
You need to run a local or remote AElf node to run the unit test successfully. If you're not familiar with how to run a node or multiple nodes, please see Running a node / Running multiple nodes for more information.