From 57e1f6d99a7d31a33fb85cf0a874c2d383d2477f Mon Sep 17 00:00:00 2001 From: Rutvik Date: Tue, 25 Jun 2024 23:25:19 +0530 Subject: [PATCH] Worked on resolved some format issues --- .../Developer Tools/Chain Sdk/_category_.json | 4 - docs/Developer Tools/Chain Sdk/csharp-sdk.md | 563 +++++++++++++----- docs/Developer Tools/Chain Sdk/go-sdk.md | 339 ++++++----- docs/Developer Tools/Chain Sdk/index.md | 6 + docs/Developer Tools/Chain Sdk/java-sdk.md | 129 ++-- .../Chain Sdk/javascript-sdk.md | 135 ++++- docs/Developer Tools/Chain Sdk/php-skd.md | 132 +++- docs/Developer Tools/Chain Sdk/python-sdk.md | 1 + docs/Developer Tools/aelf-web-login.md | 7 + .../index.md | 7 + .../command-line-Interface/Commands.md | 1 + .../command-line-Interface/Introduction.md | 1 + docs/Resources/Browser Extension/index.md | 1 + docs/Resources/DevOps/index.md | 1 + .../Wallet and Block Explorer/index.md | 1 + .../aelf-blockchain-boot-sequance.md | 10 +- docs/protocol/transactions/index.md | 7 + 17 files changed, 941 insertions(+), 404 deletions(-) delete mode 100644 docs/Developer Tools/Chain Sdk/_category_.json create mode 100644 docs/Developer Tools/Chain Sdk/index.md diff --git a/docs/Developer Tools/Chain Sdk/_category_.json b/docs/Developer Tools/Chain Sdk/_category_.json deleted file mode 100644 index 611ac3cd..00000000 --- a/docs/Developer Tools/Chain Sdk/_category_.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "position": 2, - "label": "Chain SDK" -} diff --git a/docs/Developer Tools/Chain Sdk/csharp-sdk.md b/docs/Developer Tools/Chain Sdk/csharp-sdk.md index ef06ba0f..1fbe765c 100644 --- a/docs/Developer Tools/Chain Sdk/csharp-sdk.md +++ b/docs/Developer Tools/Chain Sdk/csharp-sdk.md @@ -2,6 +2,7 @@ sidebar_position: 2 title: C# SDK description: C# SDK +image: /img/Logo.aelf.svg --- # aelf-sdk.cs - aelf C# API @@ -76,7 +77,54 @@ Console.WriteLine($"Connected: {isConnected}"); ### 3. Initiate a Transfer Transaction -#### a. Get Token Contract Address +```csharp +// Get token contract address. +var tokenContractAddress = await client.GetContractAddressByNameAsync(HashHelper.ComputeFrom("AElf.ContractNames.Token")); + +var methodName = "Transfer"; +var param = new TransferInput +{ + To = new Address {Value = Address.FromBase58("7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz").Value}, + Symbol = "ELF", + Amount = 1000000000, + Memo = "transfer in demo" +}; +var ownerAddress = client.GetAddressFromPrivateKey(PrivateKey); + +// Generate a transfer transaction. +var transaction = await client.GenerateTransaction(ownerAddress, tokenContractAddress.ToBase58(), methodName, param); +var txWithSign = client.SignTransaction(PrivateKey, transaction); + +// Send the transfer transaction to AElf chain node. +var result = await client.SendTransactionAsync(new SendTransactionInput +{ + RawTransaction = txWithSign.ToByteArray().ToHex() +}); + +await Task.Delay(4000); +// After the transaction is mined, query the execution results. +var transactionResult = await client.GetTransactionResultAsync(result.TransactionId); +Console.WriteLine(transactionResult.Status); + +// Query account balance. +var paramGetBalance = new GetBalanceInput +{ + Symbol = "ELF", + Owner = new Address {Value = Address.FromBase58(ownerAddress).Value} +}; +var transactionGetBalance =await client.GenerateTransaction(ownerAddress, tokenContractAddress.ToBase58(), "GetBalance", paramGetBalance); +var txWithSignGetBalance = client.SignTransaction(PrivateKey, transactionGetBalance); + +var transactionGetBalanceResult = await client.ExecuteTransactionAsync(new ExecuteTransactionDto +{ + RawTransaction = txWithSignGetBalance.ToByteArray().ToHex() +}); + +var balance = GetBalanceOutput.Parser.ParseFrom(ByteArrayHelper.HexstringToByteArray(transactionGetBalanceResult)); +Console.WriteLine(balance.Balance); +``` + + ## Web API +You can see how the Web API of the node works at `{chainAddress}/swagger/index.html`. For example, on a local address: `http://127.0.0.1:1235/swagger/index.html`. + Here are the examples and code snippets for interacting with the AElf Web API using the `AElfClient` instance. ### 1. Create Instance @@ -179,111 +229,235 @@ AElfClient client = new AElfClient("http://127.0.0.1:1235"); ### 2. Get Chain Status -Get the current status of the blockchain. +- **Web API path**: `/api/blockChain/chainStatus` + +- **Parameters** : None + +- **Returns**: `ChainStatusDto` + - ChainId - string + - Branches - Dictionary`` + - NotLinkedBlocks - Dictionary`` + - LongestChainHeight - long + - LongestChainHash - string + - GenesisBlockHash - string + - GenesisContractAddress - string + - LastIrreversibleBlockHash - string + - LastIrreversibleBlockHeight - long + - BestChainHash - string + - BestChainHeight - long + +#### Example: ```csharp -var chainStatus = await client.GetChainStatusAsync(); -Console.WriteLine($"Chain ID: {chainStatus.ChainId}"); -Console.WriteLine($"Best Chain Height: {chainStatus.BestChainHeight}"); +await client.GetChainStatusAsync(); ``` ### 3. Get Contract File Descriptor Set -Get the protobuf definitions related to a contract. +- **Web API path**: `/api/blockChain/contractFileDescriptorSet` + +- **Parameters** : + - contractAddress - string + +- **Returns**: `[]byte` + + +#### Example: ```csharp -string contractAddress = "YOUR_CONTRACT_ADDRESS"; -var fileDescriptorSet = await client.GetContractFileDescriptorSetAsync(contractAddress); -Console.WriteLine($"File Descriptor Set: {fileDescriptorSet.Length} bytes"); +await client.GetContractFileDescriptorSetAsync(address); ``` ### 4. Get Block Height -Get the current best height of the chain. +- **Web API path**: `/api/blockChain/blockHeight` + +- **Parameters** : None + +- **Returns**: `long` + + +#### Example: ```csharp -var blockHeight = await client.GetBlockHeightAsync(); -Console.WriteLine($"Block Height: {blockHeight}"); +await client.GetBlockHeightAsync(); ``` ### 5. Get Block Information by Block Hash -Get block information by block hash. +- **Web API path**: `/api/blockChain/block` + +- **Parameters** : + - blockHash - string + - includeTransactions - bool + +- **Returns**: `BlockDto` + + - BlockHash - string + - Header - BlockHeaderDto + - PreviousBlockHash - string + - MerkleTreeRootOfTransactions - string + - MerkleTreeRootOfWorldState - string + - Extra - string + - Height - long + - Time - string + - ChainId - string + - Bloom - string + - SignerPubkey - string + - Body - BlockBodyDto + - TransactionsCount - int + - Transactions - []string + +#### Example: ```csharp -string blockHash = "YOUR_BLOCK_HASH"; -var block = await client.GetBlockByHashAsync(blockHash); -Console.WriteLine($"Block Hash: {block.BlockHash}"); -Console.WriteLine($"Block Height: {block.Header.Height}"); +await client.GetBlockByHashAsync(blockHash); ``` ### 6. Get Block Information by Block Height -Get block information by block height. +- **Web API path**: `/api/blockChain/blockByHeight` + +- **Parameters** : + - blockHeight - long + - includeTransactions - bool + +- **Returns**: `BlockDto` + + - BlockHash - string + - Header - BlockHeaderDto + - PreviousBlockHash - string + - MerkleTreeRootOfTransactions - string + - MerkleTreeRootOfWorldState - string + - Extra - string + - Height - long + - Time - string + - ChainId - string + - Bloom - string + - SignerPubkey - string + - Body - BlockBodyDto + - TransactionsCount - int + - Transactions - []string + + +#### Example: ```csharp -long height = 100; -var blockByHeight = await client.GetBlockByHeightAsync(height); -Console.WriteLine($"Block Hash: {blockByHeight.BlockHash}"); -Console.WriteLine($"Block Height: {blockByHeight.Header.Height}"); +await client.GetBlockByHeightAsync(height); ``` ### 7. Get Transaction Result -Get the result of a transaction. +- **Web API path**: `/api/blockChain/transactionResult` + +- **Parameters** : + - transactionId - string + +- **Returns**: `TransactionResultDto` + + - TransactionId - string + - Status - string + - Logs - []LogEventDto + - Address - string + - Name - string + - Indexed - []string + - NonIndexed - string + - Bloom - string + - BlockNumber - long + - BlockHash - string + - Transaction - TransactionDto + - From - string + - To - string + - RefBlockNumber - long + - RefBlockPrefix - string + - MethodName - string + - Params - string + - Signature - string + - Error - string + + +#### Example: ```csharp -string transactionId = "YOUR_TRANSACTION_ID"; -var transactionResult = await client.GetTransactionResultAsync(transactionId); -Console.WriteLine($"Transaction Status: {transactionResult.Status}"); -Console.WriteLine($"Block Number: {transactionResult.BlockNumber}"); +await client.GetTransactionResultAsync(transactionId); ``` ### 8. Get Multiple Transaction Results in a Block -Get multiple transaction results in a block. +- **Web API path**: `/api/blockChain/transactionResults` + +- **Parameters** : + - blockHash - string + - offset - int + - limit - int + +- **Returns**: `List` - The array of transaction result: + - the transaction result object + + +#### Example: ```csharp -string blockHashForTransactions = "YOUR_BLOCK_HASH"; -var transactionResults = await client.GetTransactionResultsAsync(blockHashForTransactions, 0, 10); -foreach (var result in transactionResults) -{ - Console.WriteLine($"Transaction ID: {result.TransactionId}, Status: {result.Status}"); -} +await client.GetTransactionResultsAsync(blockHash, 0, 10); ``` ### 9. Get Transaction Pool Status -Get the transaction pool status. +- **Web API path**: `/api/blockChain/transactionPoolStatus` + +- **Parameters** : None + +- **Returns**: `TransactionPoolStatusOutput` + - Queued - int + - Validated - int + + +#### Example: ```csharp var transactionPoolStatus = await client.GetTransactionPoolStatusAsync(); -Console.WriteLine($"Queued Transactions: {transactionPoolStatus.Queued}"); -Console.WriteLine($"Validated Transactions: {transactionPoolStatus.Validated}"); ``` ### 10. Send Transaction -Broadcast a transaction. +- **Web API path**: `/api/blockChain/sendTransaction` (POST) + +- **Parameters** : + - `SendRawTransactionInput` - Serialization of data into protobuf data: + -`RawTransaction` - string + +- **Returns**: `SendRawTransactionOutput` + - TransactionId - string + + +#### Example: ```csharp -var sendTransactionInput = new SendTransactionInput -{ - RawTransaction = "YOUR_RAW_TRANSACTION" -}; var sendTransactionOutput = await client.SendTransactionAsync(sendTransactionInput); -Console.WriteLine($"Transaction ID: {sendTransactionOutput.TransactionId}"); ``` ### 11. Send Raw Transaction -Broadcast a raw transaction. +- **Web API path**: `/api/blockChain/sendTransaction` (POST) + +- **Parameters** : + - SendRawTransactionInput - Serialization of data into protobuf data: + - `Transaction` - string + - `Signature` - string + - `ReturnTransaction` - bool + +- **Returns**: `SendRawTransactionOutput` + - TransactionId - string + - Transaction - TransactionDto + + +#### Example: ```csharp var sendRawTransactionInput = new SendRawTransactionInput @@ -298,87 +472,128 @@ Console.WriteLine($"Transaction ID: {sendRawTransactionOutput.TransactionId}"); ### 12. Send Multiple Transactions -Broadcast multiple transactions. +- **Web API path**: `/api/blockChain/sendTransactions` (POST) + +- **Parameters** : + - `SendTransactionsInput` - Serialization of data into protobuf data: + - `SendTransactionsInput` - string + +- **Returns**: `string[]` + + +#### Example: ```csharp -var sendTransactionsInput = new SendTransactionsInput -{ - RawTransactions = new[] { "RAW_TRANSACTION_1", "RAW_TRANSACTION_2" } -}; -var transactionIds = await client.SendTransactionsAsync(sendTransactionsInput); -foreach (var id in transactionIds) -{ - Console.WriteLine($"Transaction ID: {id}"); -} +await client.SendTransactionsAsync(input); ``` ### 13. Create Raw Transaction -Creates an unsigned serialized transaction. +- **Web API path**: `/api/blockChain/rawTransaction` (POST) + +- **Parameters** : + - `CreateRawTransactionInput` + - `From` - string + - `To` - string + - `RefBlockNumber` - long + - `RefBlockHash` - string + - `MethodName` - string + - `Params` - string + +- **Returns**: + - `CreateRawTransactionOutput` + - `RawTransactions` - string + + +#### Example: ```csharp -var createRawTransactionInput = new CreateRawTransactionInput -{ - From = "FROM_ADDRESS", - To = "TO_ADDRESS", - RefBlockNumber = 100, - RefBlockHash = "BLOCK_HASH", - MethodName = "METHOD_NAME", - Params = "PARAMETERS" -}; -var createRawTransactionOutput = await client.CreateRawTransactionAsync(createRawTransactionInput); -Console.WriteLine($"Raw Transaction: {createRawTransactionOutput.RawTransaction}"); +await client.CreateRawTransactionAsync(input); ``` ### 14. Execute Transaction -Call a read-only method on a contract. +- **Web API path**: `/api/blockChain/executeTransaction` (POST) + +- **Parameters** : + - `ExecuteRawTransactionDto` - Serialization of data into protobuf data: + - `RawTransaction` - string + +- **Returns**: `string` + + +#### Example: ```csharp -var executeTransactionDto = new ExecuteTransactionDto -{ - RawTransaction = "YOUR_RAW_TRANSACTION" -}; -var executionResult = await client.ExecuteTransactionAsync(executeTransactionDto); -Console.WriteLine($"Execution Result: {executionResult}"); +await client.ExecuteRawTransactionAsync(input); ``` ### 15. Execute Raw Transaction -Call a read-only method on a contract with a raw transaction. +- **Web API path**: `/api/blockChain/executeRawTransaction` (POST) +- **Parameters** : + - `ExecuteRawTransactionDto` - Serialization of data into protobuf data: + - `RawTransaction` - string + - `Signature` - string + +- **Returns**: `string` + + +#### Example: ```csharp -var executeRawTransactionDto = new ExecuteRawTransactionDto -{ - RawTransaction = "YOUR_RAW_TRANSACTION", - Signature = "YOUR_SIGNATURE" -}; -var executeRawResult = await client.ExecuteRawTransactionAsync(executeRawTransactionDto); -Console.WriteLine($"Execution Result: {executeRawResult}"); +await client.ExecuteRawTransactionAsync(input); ``` ### 16. Get Peers -Get peer info about the connected network nodes. +- **Web API path**: `/api/net/peers` + +- **Parameters** : + - `withMetrics` - bool + +- **Returns**: `List` + + - `IpAddress` - string + - `ProtocolVersion` - int + - `ConnectionTime` - long + - `ConnectionStatus` - string + - `Inbound` - bool + - `BufferedTransactionsCount` - int + - `BufferedBlocksCount` - int + - `BufferedAnnouncementsCount` - int + - `NodeVersion` - string + - `RequestMetrics` - List`` + - `RoundTripTime` - long + - `MethodName` - string + - `Info` - string + - `RequestTime` - string + + + +#### Example: ```csharp -var peers = await client.GetPeersAsync(false); -foreach (var peer in peers) -{ - Console.WriteLine($"Peer IP: {peer.IpAddress}, Connection Status: {peer.ConnectionStatus}"); -} +await client.GetPeersAsync(false); ``` ### 17. Add Peer -Attempts to add a node to the connected network nodes. +Attempts to remove a node from the connected network nodes. + +- **Web API path**: `/api/net/peer` (POST) + +- **Parameters** : + - `ipAddress` - string +- **Returns**: `bool` + +#### Example: ```csharp -var isPeerAdded = await client.AddPeerAsync("127.0.0.1:7001"); -Console.WriteLine($"Peer Added: {isPeerAdded}"); +await client.AddPeerAsync("127.0.0.1:7001"); ``` @@ -386,33 +601,61 @@ Console.WriteLine($"Peer Added: {isPeerAdded}"); Attempts to remove a node from the connected network nodes. +- **Web API path**: `/api/net/peer` (DELETE) + +- **Parameters** : + - `ipAddress` - string + +- **Returns**: `bool` + ```csharp -var isPeerRemoved = await client.RemovePeerAsync("127.0.0.1:7001"); -Console.WriteLine($"Peer Removed: {isPeerRemoved}"); +await client.RemovePeerAsync("127.0.0.1:7001"); ``` ### 19. Calculate Transaction Fee +- **Web API path**: `/api/blockChain/calculateTransactionFee` (POST) + +- **Parameters** : + - `CalculateTransactionFeeInput` - The object with the following structure : + - `RawTrasaction` - string + +- **Returns**: + - `TransactionFeeResultOutput` + - `Success` - bool + - `TransactionFee` - map[string]interface{} + - `ResourceFee` - map[string]interface{} + +#### Example: + ```csharp -var calculateTransactionFeeInput = new CalculateTransactionFeeInput -{ - RawTransaction = "YOUR_RAW_TRANSACTION" +var input = new CalculateTransactionFeeInput{ + RawTransaction = RawTransaction }; -var transactionFeeResult = await client.CalculateTransactionFeeAsync(calculateTransactionFeeInput); -Console.WriteLine($"Transaction Fee: {transactionFeeResult.TransactionFee}"); +await Client.CalculateTransactionFeeAsync(input); ``` ### 20. Get Network Information +- **Web API path**: `/api/net/networkInfo` + +- **Parameters** : Empty + +- **Returns**: + - `NetworkInfoOutput` + - `Version` - string + - `ProtocolVersion` - int + - `Connections` - int + +#### Example: + ```csharp -var networkInfo = await client.GetNetworkInfoAsync(); -Console.WriteLine($"Network Version: {networkInfo.Version}"); -Console.WriteLine($"Connections: {networkInfo.Connections}"); +await client.GetNetworkInfoAsync(); ``` -These examples demonstrate how to use the AElf Web API in C# using the `AElfClient` class to interact with the AElf blockchain, including checking chain status, handling transactions, and managing network peers. +These examples demonstrate how to use the aelf Web API in C# using the `AElfClient` class to interact with the aelf blockchain, including checking chain status, handling transactions, and managing network peers. ## aelf Client @@ -421,6 +664,13 @@ These examples demonstrate how to use the AElf Web API in C# using the `AElfClie Verify whether this SDK successfully connects to the chain. +- **Parameters**: None + +- **Returns** : + - `bool`: Connection status + +#### Example: + ```csharp bool isConnected = await client.IsConnectedAsync(); Console.WriteLine($"Is Connected: {isConnected}"); @@ -430,92 +680,131 @@ Console.WriteLine($"Is Connected: {isConnected}"); Get the address of the genesis contract. +- **Parameters**: None + +- **Returns** : + - `string`: Genesis contract address + +#### Example: ```csharp -string genesisContractAddress = await client.GetGenesisContractAddressAsync(); -Console.WriteLine($"Genesis Contract Address: {genesisContractAddress}"); +await client.GetGenesisContractAddressAsync(); ``` ### 3. GetContractAddressByName Get the address of a contract by the given contract name hash. +- **Parameters**: + - `contractNameHash` (string): Hash of the contract name + +- **Returns** : + - `string`: Contract address + +#### Example: ```csharp -var contractNameHash = HashHelper.ComputeFrom("AElf.ContractNames.Token"); -string contractAddress = await client.GetContractAddressByNameAsync(contractNameHash); -Console.WriteLine($"Contract Address: {contractAddress}"); +await client.GetContractAddressByNameAsync(contractNameHash); ``` ### 4. GenerateTransaction Build a transaction from the input parameters. +- **Parameters**: + - `from` (string): Sender's address + - `to` (string): Recipient's address + - `methodName` (string): Method name + - `input` IMessage -```csharp -string from = "FROM_ADDRESS"; -string to = "TO_ADDRESS"; -string methodName = "Transfer"; -var input = new TransferInput -{ - To = new Address { Value = Address.FromBase58("TO_ADDRESS").Value }, - Symbol = "ELF", - Amount = 1000000000, - Memo = "Transfer example" -}; +- **Returns** : + - `Transaction`: Built transaction + +#### Example: -Transaction transaction = await client.GenerateTransactionAsync(from, to, methodName, input); -Console.WriteLine($"Transaction: {transaction}"); +```csharp +await client.GenerateTransactionAsync(from, to, methodName, input); ``` ### 5. GetFormattedAddress Convert the `Address` to the displayed string format: symbol_base58-string_base58-string_chain-id. +- **Parameters**: + - `address` (string): Address to format + +- **Returns** : + - `string`: Formatted address + +#### Example: + ```csharp -Address address = new Address { Value = Address.FromBase58("ADDRESS").Value }; -string formattedAddress = await client.GetFormattedAddressAsync(address); -Console.WriteLine($"Formatted Address: {formattedAddress}"); +await client.GetFormattedAddressAsync(address); ``` ### 6. SignTransaction +- **Parameters**: + - `privateKey` (string): Address to format + - `transaction` (string): Address to format + +- **Returns** : + - `Transaction` + +#### Example: + ```csharp -string privateKeyHex = "YOUR_PRIVATE_KEY_HEX"; -Transaction signedTransaction = client.SignTransaction(privateKeyHex, transaction); -Console.WriteLine($"Signed Transaction: {signedTransaction}"); +client.SignTransaction(privateKeyHex, transaction); ``` ### 7. GetAddressFromPubKey Get the account address through the public key. +- **Parameters**: + - `pubKey` (string): Public key + +- **Returns** : + - `string`: Account address + +#### Example: + ```csharp -string pubKey = "YOUR_PUBLIC_KEY"; -string addressFromPubKey = client.GetAddressFromPubKey(pubKey); -Console.WriteLine($"Address from PubKey: {addressFromPubKey}"); +client.GetAddressFromPubKey(pubKey); ``` ### 8. GetAddressFromPrivateKey Get the account address through the private key. +- **Parameters**: + - `privateKey` (string): Private key + +- **Returns** : + - `string`: Account address + +#### Example: + ```csharp -string privateKeyHex = "YOUR_PRIVATE_KEY_HEX"; -string addressFromPrivateKey = client.GetAddressFromPrivateKey(privateKeyHex); -Console.WriteLine($"Address from Private Key: {addressFromPrivateKey}"); +client.GetAddressFromPrivateKey(privateKeyHex); ``` ### 9. GenerateKeyPairInfo Generate a new account key pair. +- **Parameters**: None + +- **Returns** : + - `KeyPairInfo` + - `PrivateKey` - string + - `PublicKey` - string + - `Address` - string + +#### Example: ```csharp -var keyPairInfo = client.GenerateKeyPairInfo(); -Console.WriteLine($"Private Key: {keyPairInfo.PrivateKey}"); -Console.WriteLine($"Public Key: {keyPairInfo.PublicKey}"); -Console.WriteLine($"Address: {keyPairInfo.Address}"); +client.GenerateKeyPairInfo(); ``` ## Supports diff --git a/docs/Developer Tools/Chain Sdk/go-sdk.md b/docs/Developer Tools/Chain Sdk/go-sdk.md index c87e132e..c48bc49f 100644 --- a/docs/Developer Tools/Chain Sdk/go-sdk.md +++ b/docs/Developer Tools/Chain Sdk/go-sdk.md @@ -2,19 +2,18 @@ sidebar_position: 3 title: Go SDK description: Go SDK +image: /img/Logo.aelf.svg --- # aelf-sdk.go - aelf Go API ## Introduction ----------- This document provides information on how to use the AElf Go SDK (aelf-sdk.go) to interact with an AElf node. The SDK allows you to communicate with a local or remote AElf node using HTTP. Here you will find instructions for setting up the SDK, examples of how to use it, and a brief description of its main functions. For additional information, please visit the repository: [aelf-sdk.go](https://github.com/AElfProject/aelf-sdk.go) ## Installation ----------- To install the `aelf-sdk.go` package, run the following command: @@ -23,7 +22,6 @@ go get -u github.com/AElfProject/aelf-sdk.go ``` ## Examples ----------- ### Create instance @@ -31,15 +29,7 @@ go get -u github.com/AElfProject/aelf-sdk.go Create a new instance of `AElfClient` and set the URL of an AElf chain node: ```go -import ( - "github.com/AElfProject/aelf-sdk.go/client" - "github.com/AElfProject/aelf-sdk.go/util" - "github.com/AElfProject/aelf-sdk.go/pb" - "github.com/golang/protobuf/proto" - "encoding/hex" - "fmt" - "time" -) +import ("github.com/AElfProject/aelf-sdk.go/client") var aelf = client.AElfClient{ Host: "http://127.0.0.1:8000", @@ -52,18 +42,14 @@ var aelf = client.AElfClient{ Here is an example of how to initiate a transfer transaction using the aelf Go SDK: -#### 1. Get the Token Contract Address: ```go +// Get token contract address. tokenContractAddress, _ := aelf.GetContractAddressByName("AElf.ContractNames.Token") fromAddress := aelf.GetAddressFromPrivateKey(aelf.PrivateKey) methodName := "Transfer" toAddress, _ := util.Base58StringToAddress("7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz") -``` - -#### 2. Set Transaction Parameters: -```go params := &pb.TransferInput{ To: toAddress, Symbol: "ELF", @@ -71,30 +57,21 @@ params := &pb.TransferInput{ Memo: "transfer in demo", } paramsByte, _ := proto.Marshal(params) -``` - -#### 3. Generate and Sign the Transaction: -```go +// Generate a transfer transaction. transaction, _ := aelf.CreateTransaction(fromAddress, tokenContractAddress, methodName, paramsByte) signature, _ := aelf.SignTransaction(aelf.PrivateKey, transaction) transaction.Signature = signature -``` - -#### 4. Send the Transaction to the AElf Chain Node: -```go -transactionBytes, _ := proto.Marshal(transaction) -sendResult, _ := aelf.SendTransaction(hex.EncodeToString(transactionBytes)) +// Send the transfer transaction to AElf chain node. +transactionByets, _ := proto.Marshal(transaction) +sendResult, _ := aelf.SendTransaction(hex.EncodeToString(transactionByets)) time.Sleep(time.Duration(4) * time.Second) transactionResult, _ := aelf.GetTransactionResult(sendResult.TransactionID) fmt.Println(transactionResult) -``` - -#### 5. Query Account Balance: -```go +// Query account balance. ownerAddress, _ := util.Base58StringToAddress(fromAddress) getBalanceInput := &pb.GetBalanceInput{ Symbol: "ELF", @@ -107,8 +84,8 @@ getBalanceTransaction.Params = getBalanceInputByte getBalanceSignature, _ := aelf.SignTransaction(aelf.PrivateKey, getBalanceTransaction) getBalanceTransaction.Signature = getBalanceSignature -getBalanceTransactionBytes, _ := proto.Marshal(getBalanceTransaction) -getBalanceResult, _ := aelf.ExecuteTransaction(hex.EncodeToString(getBalanceTransactionBytes)) +getBalanceTransactionByets, _ := proto.Marshal(getBalanceTransaction) +getBalanceResult, _ := aelf.ExecuteTransaction(hex.EncodeToString(getBalanceTransactionByets)) balance := &pb.GetBalanceOutput{} getBalanceResultBytes, _ := hex.DecodeString(getBalanceResult) proto.Unmarshal(getBalanceResultBytes, balance) @@ -118,16 +95,13 @@ fmt.Println(balance) ## Web API ----------- You can see how the Web API of the node works at `{chainAddress}/swagger/index.html`. For example, on a local address: `http://127.0.0.1:1235/swagger/index.html`. The usage of these methods is based on the `AElfClient` instance. If you don’t have one, please create it: ```go -import ( - "github.com/AElfProject/aelf-sdk.go/client" -) +import ("github.com/AElfProject/aelf-sdk.go/client") var aelf = client.AElfClient{ Host: "http://127.0.0.1:8000", @@ -143,18 +117,20 @@ var aelf = client.AElfClient{ - **Parameters** : None -- **Returns**: `ChainStatusDto` - - ChainId - string - - Branches - map[string]interface{} - - NotLinkedBlocks - map[string]interface{} - - LongestChainHeight - int64 - - LongestChainHash - string - - GenesisBlockHash - string - - GenesisContractAddress - string - - LastIrreversibleBlockHash - string - - LastIrreversibleBlockHeight - int64 - - BestChainHash - string - - BestChainHeight - int64 +- **Returns**: + - `ChainStatusDto` + + - `ChainId` - string + - `Branches` - map[string]interface{} + - `NotLinkedBlocks` - map[string]interface{} + - `LongestChainHeight` - int64 + - `LongestChainHash` - string + - `GenesisBlockHash` - string + - `GenesisContractAddress` - string + - `LastIrreversibleBlockHash` - string + - `LastIrreversibleBlockHeight` - int64 + - `BestChainHash` - string + - `BestChainHeight` - int64 #### Example: @@ -206,25 +182,27 @@ Get block information by block hash. - **Web API path**: `/api/blockChain/block` - **Parameters** : - - blockHash - string - - includeTransactions - bool - -- **Returns**: `BlockDto` - - - BlockHash - string - - Header - BlockHeaderDto - - PreviousBlockHash - string - - MerkleTreeRootOfTransactions - string - - MerkleTreeRootOfWorldState - string - - Extra - string - - Height - int64 - - Time - string - - ChainId - string - - Bloom - string - - SignerPubkey - string - - Body - BlockBodyDto - - TransactionsCount - int - - Transactions - []string + - `blockHash` - string + - `includeTransactions` - bool + +- **Returns**: + + - `BlockDto` + + - `BlockHash` - string + - `Header` - BlockHeaderDto + - `PreviousBlockHash` - string + - `MerkleTreeRootOfTransactions` - string + - `MerkleTreeRootOfWorldState` - string + - `Extra` - string + - `Height` - int64 + - `Time` - string + - `ChainId` - string + - `Bloom` - string + - `SignerPubkey` - string + - `Body` - BlockBodyDto + - `TransactionsCount` - int + - `Transactions` - []string #### Example: @@ -239,25 +217,27 @@ block, err := aelf.GetBlockByHash(blockHash, true) - **Web API path**: `/api/blockChain/blockByHeight` - **Parameters** : - - blockHeight - int64 - - includeTransactions - bool - -- **Returns**: `BlockDto` - - - BlockHash - string - - Header - BlockHeaderDto - - PreviousBlockHash - string - - MerkleTreeRootOfTransactions - string - - MerkleTreeRootOfWorldState - string - - Extra - string - - Height - int64 - - Time - string - - ChainId - string - - Bloom - string - - SignerPubkey - string - - Body - BlockBodyDto - - TransactionsCount - int - - Transactions - []string + - `blockHeight` - int64 + - `includeTransactions` - bool + +- **Returns**: + + - `BlockDto` + + - `BlockHash` - string + - `Header` - BlockHeaderDto + - `PreviousBlockHash` - string + - `MerkleTreeRootOfTransactions` - string + - `MerkleTreeRootOfWorldState` - string + - `Extra` - string + - `Height` - int64 + - `Time` - string + - `ChainId` - string + - `Bloom` - string + - `SignerPubkey` - string + - `Body` - BlockBodyDto + - `TransactionsCount` - int + - `Transactions` - []string #### Example: @@ -271,30 +251,32 @@ block, err := aelf.GetBlockByHeight(100, true) - **Web API path**: `/api/blockChain/transactionResult` - **Parameters** : - - transactionId - string - -- **Returns**: `TransactionResultDto` - - - TransactionId - string - - Status - string - - Logs - []LogEventDto - - Address - string - - Name - string - - Indexed - []string - - NonIndexed - string - - Bloom - string - - BlockNumber - int64 - - BlockHash - string - - Transaction - TransactionDto - - From - string - - To - string - - RefBlockNumber - int64 - - RefBlockPrefix - string - - MethodName - string - - Params - string - - Signature - string - - ReturnValue - string - - Error - string + - `transactionId` - string + +- **Returns**: + + - `TransactionResultDto` + + - `TransactionId` - string + - `Status` - string + - `Logs` - []LogEventDto + - `Address` - string + - `Name` - string + - `Indexed` - []string + - `NonIndexed` - string + - `Bloom` - string + - `BlockNumber` - int64 + - `BlockHash` - string + - `Transaction` - TransactionDto + - `From` - string + - `To` - string + - `RefBlockNumber` - int64 + - `RefBlockPrefix` - string + - `MethodName` - string + - `Params` - string + - `Signature` - string + - `ReturnValue` - string + - `Error` - string #### Example: @@ -311,9 +293,9 @@ Get multiple transaction results in a block. - **Web API path**: `/api/blockChain/transactionResults` - **Parameters** : - - blockHash - string - - offset - int - - limit - int + - `blockHash` - string + - `offset` - int + - `limit` - int - **Returns**: `[]TransactionResultDto` - the transaction result object @@ -330,10 +312,11 @@ transactionResults, err := aelf.GetTransactionResults(blockHash, 0, 10) - **Web API path**: `/api/blockChain/transactionPoolStatus` - **Parameters** : None + - **Returns**: `TransactionPoolStatusOutput` - - Queued - int - - Validated - int + - `Queued` - int + - `Validated` - int #### Example: @@ -347,12 +330,36 @@ poolStatus, err := aelf.GetTransactionPoolStatus(); - **Web API path**: `/api/blockChain/sendTransaction` (POST) - **Parameters** : - - SendRawTransactionInput - struct containing `Transaction` as string, `Signature` as string, and `ReturnTransaction` as bool + - `SendRawTransactionInput` - Serialization of data into protobuf data: + - `RawTransaction` - string + +- **Returns**: + + - `SendTransactionOutput` + - `TransactionId` - string + + +#### Example: + +```go +sendResult, err := aelf.SendTransaction(input) +``` + +### SendRawTransaction + +- **Web API path**: `/api/blockChain/sendTransaction` (POST) + +- **Parameters** : + - `SendRawTransactionInput` - Serialization of data into protobuf data: + - `RawTransaction` - string + - `Signature` - string + - `ReturnTransaction` - bool -- **Returns**: `SendRawTransactionOutput` +- **Returns**: - - TransactionId - string - - Transaction - TransactionDto + - `SendRawTransactionOutput` + - `TransactionId` - string + - `Transaction` - TransactionDto #### Example: @@ -362,12 +369,13 @@ sendRawResult, err := aelf.SendRawTransaction(input) ``` + ### SendTransactions - **Web API path**: `/api/blockChain/sendTransactions` (POST) - **Parameters** : - - rawTransactions - string + - `rawTransactions` - string - - Serialization of data into protobuf data: - **Returns**: `[]interface{}` @@ -387,9 +395,19 @@ Creates an unsigned serialized transaction. - **Web API path**: `/api/blockChain/rawTransaction` (POST) - **Parameters** : - - CreateRawTransactionInput - struct containing `From`, `To`, `RefBlockNumber`, `RefBlockHash`, `MethodName`, `Params` -- **Returns**: `CreateRawTransactionOutput` + - `CreateRawTransactionInput` + - `From` - string + - `To` - string + - `RefBlockNumber` - long + - `RefBlockHash` - string + - `MethodName` - string + - `Params` - string + +- **Returns**: + + - `CreateRawTransactionOutput` + - `RawTransactions` - string #### Example: @@ -407,7 +425,7 @@ Call a read-only method on a contract. - **Web API path**: `/api/blockChain/executeTransaction` (POST) - **Parameters** : - - rawTransaction - string + - `rawTransaction` - string - **Returns**: `string` @@ -427,7 +445,9 @@ Call a read-only method on a contract. - **Web API path**: `/api/blockChain/executeRawTransaction` (POST) - **Parameters** : - - ExecuteRawTransactionDto - struct containing `RawTransaction` as string, `Signature` as string + - `ExecuteRawTransactionDto` - Serialization of data into protobuf data: + - `RawTransaction` - string + - `Signature` - string - **Returns**: `string` @@ -443,28 +463,29 @@ executeRawresult, err := aelf.ExecuteRawTransaction(executeRawinput) Get peer info about the connected network nodes. - - **Web API path**: `/api/net/peers` - **Parameters** : - - withMetrics - bool + - `withMetrics` - bool -- **Returns**: `[]PeerDto` +- **Returns**: - - IpAddress - string - - ProtocolVersion - int - - ConnectionTime - int64 - - ConnectionStatus - string - - Inbound - bool - - BufferedTransactionsCount - int - - BufferedBlocksCount - int - - BufferedAnnouncementsCount - int - - NodeVersion - string - - RequestMetrics - []RequestMetric - - RoundTripTime - int64 - - MethodName - string - - Info - string - - RequestTime - string + - `[]PeerDto` + + - `IpAddress` - string + - `ProtocolVersion` - int + - `ConnectionTime` - int64 + - `ConnectionStatus` - string + - `Inbound` - bool + - `BufferedTransactionsCount` - int + - `BufferedBlocksCount` - int + - `BufferedAnnouncementsCount` - int + - `NodeVersion` - string + - `RequestMetrics` - []RequestMetric + - `RoundTripTime` - int64 + - `MethodName` - string + - `Info` - string + - `RequestTime` - string @@ -483,7 +504,8 @@ Attempts to add a node to the connected network nodes. - **Web API path**: `/api/net/peer` (POST) - **Parameters** : - - ipAddress - string + + - `ipAddress` - string - **Returns**: `bool` @@ -502,7 +524,8 @@ Attempts to remove a node from the connected network nodes. - **Web API path**: `/api/net/peer` (DELETE) - **Parameters** : - - ipAddress - string + + - `ipAddress` - string - **Returns**: `bool` @@ -521,12 +544,14 @@ Estimate transaction fee. - **Web API path**: `/api/blockChain/calculateTransactionFee` (POST) - **Parameters** : - - CalculateTransactionFeeInput - struct containing `RawTransaction` as string + - `CalculateTransactionFeeInput` - The object with the following structure : + - `RawTrasaction` - string -- **Returns**: `TransactionFeeResultOutput` - - Success - bool - - TransactionFee - map[string]interface{} - - ResourceFee - map[string]interface{} +- **Returns**: + - `TransactionFeeResultOutput` + - `Success` - bool + - `TransactionFee` - map[string]interface{} + - `ResourceFee` - map[string]interface{} #### Example: @@ -544,10 +569,12 @@ Get the network information of the node. - **Parameters** : Empty -- **Returns**: `NetworkInfoOutput` - - Version - string - - ProtocolVersion - int - - Connections - int +- **Returns**: + + - `NetworkInfoOutput` + - `Version` - string + - `ProtocolVersion` - int + - `Connections` - int #### Example: @@ -695,7 +722,11 @@ address := aelf.GetAddressFromPrivateKey(privateKey) - **Parameters**: None - **Returns** : - - `KeyPairInfo`: Contains PrivateKey, PublicKey, and Address + + - `KeyPairInfo` + - `PrivateKey` + - `PublicKey` + - `Address` #### Example: diff --git a/docs/Developer Tools/Chain Sdk/index.md b/docs/Developer Tools/Chain Sdk/index.md new file mode 100644 index 00000000..09772988 --- /dev/null +++ b/docs/Developer Tools/Chain Sdk/index.md @@ -0,0 +1,6 @@ +--- +sidebar_position: 2 +title: Chain SDK +description: Chain SDK +image: /img/Logo.aelf.svg +--- \ No newline at end of file diff --git a/docs/Developer Tools/Chain Sdk/java-sdk.md b/docs/Developer Tools/Chain Sdk/java-sdk.md index a68d1587..54d23248 100644 --- a/docs/Developer Tools/Chain Sdk/java-sdk.md +++ b/docs/Developer Tools/Chain Sdk/java-sdk.md @@ -2,6 +2,7 @@ sidebar_position: 4 title: JAVA SDK description: JAVA SDK +image: /img/Logo.aelf.svg --- # aelf-sdk.java - aelf Java API @@ -48,63 +49,40 @@ boolean isConnected = client.isConnected(); ### Initiate a Transfer Transaction -Initiate a transfer transaction using the following steps: - -#### 1. Get Token Contract Address ```java -Copy code +// Get token contract address. String tokenContractAddress = client.getContractAddressByName(privateKey, Sha256.getBytesSha256("AElf.ContractNames.Token")); -``` -#### 2. Set Recipient Address - -```java Client.Address.Builder to = Client.Address.newBuilder(); to.setValue(ByteString.copyFrom(Base58.decodeChecked("7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz"))); Client.Address toObj = to.build(); -``` - -#### 3. Create Transfer Input -```java TokenContract.TransferInput.Builder paramTransfer = TokenContract.TransferInput.newBuilder(); paramTransfer.setTo(toObj); paramTransfer.setSymbol("ELF"); paramTransfer.setAmount(1000000000); paramTransfer.setMemo("transfer in demo"); TokenContract.TransferInput paramTransferObj = paramTransfer.build(); -``` - -#### 4. Generate and Sign Transaction -```java String ownerAddress = client.getAddressFromPrivateKey(privateKey); + Transaction.Builder transactionTransfer = client.generateTransaction(ownerAddress, tokenContractAddress, "Transfer", paramTransferObj.toByteArray()); Transaction transactionTransferObj = transactionTransfer.build(); transactionTransfer.setSignature(ByteString.copyFrom(ByteArrayHelper.hexToByteArray(client.signTransaction(privateKey, transactionTransferObj)))); transactionTransferObj = transactionTransfer.build(); -``` - -#### 5. Send Transaction -```java +// Send the transfer transaction to AElf chain node. SendTransactionInput sendTransactionInputObj = new SendTransactionInput(); sendTransactionInputObj.setRawTransaction(Hex.toHexString(transactionTransferObj.toByteArray())); SendTransactionOutput sendResult = client.sendTransaction(sendTransactionInputObj); -``` - -#### 6. Query Execution Results -```java Thread.sleep(4000); +// After the transaction is mined, query the execution results. TransactionResultDto transactionResult = client.getTransactionResult(sendResult.getTransactionId()); System.out.println(transactionResult.getStatus()); -``` -#### 7. Query Account Balance - -```java +// Query account balance. Client.Address.Builder owner = Client.Address.newBuilder(); owner.setValue(ByteString.copyFrom(Base58.decodeChecked(ownerAddress))); Client.Address ownerObj = owner.build(); @@ -225,9 +203,9 @@ Get block information by block hash. - `blockHash` - String - `includeTransactions` - boolean (true to include transaction ids list in the block, false otherwise) -**Returns**: `BlockDto` +**Returns**: - - `json` + - `BlockDto` - `BlockHash` - String - `Header` - BlockHeaderDto - `PreviousBlockHash` - String @@ -261,9 +239,9 @@ client.getBlockByHash(blockHash); - `blockHeight` - long - `includeTransactions` - boolean (true to include transaction ids list in the block, false otherwise) -**Returns**: `BlockDto` +**Returns**: - - `json` + - `BlockDto` - `BlockHash` - String - `Header` - BlockHeaderDto - `PreviousBlockHash` - String @@ -351,10 +329,11 @@ client.getTransactionResults(blockHash, 0, 10); **Parameters:**: None -**Returns**: `TransactionPoolStatusOutput` +**Returns**: -- `Queued` - int -- `Validated` - int + - `TransactionPoolStatusOutput` + - `Queued` - int + - `Validated` - int **Example**: @@ -374,9 +353,10 @@ client.getTransactionPoolStatus(); - `SendTransactionInput` - Serialization of data into protobuf format: - `RawTransaction` - String -**Returns**: `SendTransactionOutput` +**Returns**: -- `TransactionId` - String + - `SendTransactionOutput` + - `TransactionId` - String **Example**: @@ -398,10 +378,11 @@ client.sendTransaction(input); - `Signature` - String - `ReturnTransaction` - boolean -**Returns**: `SendRawTransactionOutput` +**Returns**: - - `TransactionId` - String - - `Transaction` - TransactionDto + - `SendRawTransactionOutput` + - `TransactionId` - String + - `Transaction` - TransactionDto **Example**: @@ -452,9 +433,10 @@ Create an unsigned serialized transaction. - `MethodName` - String - `Params` - String -**Returns**: `CreateRawTransactionOutput` - Serialization of data into protobuf format: +**Returns**: -- `RawTransaction` - String + - `CreateRawTransactionOutput` - Serialization of data into protobuf format: + - `RawTransaction` - String **Example**: @@ -515,22 +497,23 @@ Get peer information about the connected network nodes. - `withMetrics` - boolean -**Returns**: `List` - -- `IpAddress` - String -- `ProtocolVersion` - int -- `ConnectionTime` - long -- `ConnectionStatus` - String -- `Inbound` - boolean -- `BufferedTransactionsCount` - int -- `BufferedBlocksCount` - int -- `BufferedAnnouncementsCount` - int -- `NodeVersion` - String -- `RequestMetrics` - List`` -- `RoundTripTime` - long -- `MethodName` - String -- `Info` - String -- `RequestTime` - String +**Returns**: + + - `List` + - `IpAddress` - String + - `ProtocolVersion` - int + - `ConnectionTime` - long + - `ConnectionStatus` - String + - `Inbound` - boolean + - `BufferedTransactionsCount` - int + - `BufferedBlocksCount` - int + - `BufferedAnnouncementsCount` - int + - `NodeVersion` - String + - `RequestMetrics` - List`` + - `RoundTripTime` - long + - `MethodName` - String + - `Info` - String + - `RequestTime` - String **Example**: @@ -597,12 +580,13 @@ Estimate transaction fee. - `CalculateTransactionFeeInput` - `RawTransaction` - String -**Returns**: `CalculateTransactionFeeOutput` - -- `Success` - boolean -- `TransactionFee` - HashMap`` -- `ResourceFee` - HashMap`` +**Returns**: + - `CalculateTransactionFeeOutput` + - `Success` - boolean + - `TransactionFee` - HashMap`` + - `ResourceFee` - HashMap`` + **Example**: ```java @@ -617,11 +601,12 @@ CalculateTransactionFeeOutput output = client.calculateTransactionFee(input); **Parameters:** None -**Returns**: `NetworkInfoOutput` +**Returns**: -- `Version` - String -- `ProtocolVersion` - int -- `Connections` - int + - `NetworkInfoOutput` + - `Version` - String + - `ProtocolVersion` - int + - `Connections` - int **Example**: @@ -773,11 +758,13 @@ client.getAddressFromPrivateKey(privateKey); **Parameters:** None -**Returns**: `KeyPairInfo` +**Returns**: -- `PrivateKey` - String -- `PublicKey` - String -- `Address` - String + - `KeyPairInfo` + + - `PrivateKey` - String + - `PublicKey` - String + - `Address` - String **Example**: diff --git a/docs/Developer Tools/Chain Sdk/javascript-sdk.md b/docs/Developer Tools/Chain Sdk/javascript-sdk.md index 20c9c1b5..3e0cd155 100644 --- a/docs/Developer Tools/Chain Sdk/javascript-sdk.md +++ b/docs/Developer Tools/Chain Sdk/javascript-sdk.md @@ -2,6 +2,7 @@ sidebar_position: 1 title: Javascript SDK description: Javascript SDK +image: /img/Logo.aelf.svg --- # aelf-sdk.js - aelf JavaScript API @@ -170,6 +171,8 @@ You can access the Web API of your aelf node at `{chainAddress}/swagger/index.ht For example, if your local node address is `http://127.0.0.1:1235`, you can view the Web API at `http://127.0.0.1:1235/swagger/index.html`. +parameters and returns based on the URL: [https://aelf-public-node.aelf.io/swagger/index.html](https://aelf-public-node.aelf.io/swagger/index.html) + The methods below use an instance of aelf. If you don't have one, create it as shown: ```javascript @@ -186,7 +189,19 @@ Get the current status of the blockchain. - **Web API Path**: `/api/blockChain/chainStatus` - **Method**: GET - **Parameters**: None -- **Returns**: Object with details like ChainId, LongestChainHeight, GenesisContractAddress, etc. +- **Returns**: `Object` + + - `ChainId` - String + - `Branches` - Object + - `NotLinkedBlocks` - Object + - `LongestChainHeight` - Number + - `LongestChainHash` - String + - `GenesisBlockHash` - String + - `GenesisContractAddress` - String + - `LastIrreversibleBlockHash` - String + - `LastIrreversibleBlockHeight` - Number + - `BestChainHash` - String + - `BestChainHeight` - Number #### Example: @@ -206,7 +221,7 @@ Get the protobuf definitions related to a contract. - **Web API Path**: `/api/blockChain/contractFileDescriptorSet` - **Method**: GET - **Parameters**: `contractAddress` (String) -- **Returns**: String. +- **Returns**: `String`. #### Example: @@ -227,7 +242,7 @@ Get the current best height of the chain. - **Web API Path**: `/api/blockChain/blockHeight` - **Method**: GET - **Parameters**: None -- **Returns**: Number. +- **Returns**: `Number`. #### Example: @@ -246,10 +261,31 @@ Get block information by block hash. - **Web API Path**: `/api/blockChain/block` - **Method**: GET -- **Parameters**: `contractAddress` (String) +- **Parameters**: - **`blockHash`** (String) - **`includeTransactions`** (Boolean) -- **Returns**: object with block details + - `true` require transaction ids list in the block + - `false` Doesn’t require transaction ids list in the block + +- **Returns**: `Object` + + - `BlockHash` - String + + - `Header` - Object + - `PreviousBlockHash` - String + - `MerkleTreeRootOfTransactions` - String + - `MerkleTreeRootOfWorldState` - String + - `Extra` - Array + - `Height` - Number + - `Time` - google.protobuf.Timestamp + - `ChainId` - String + - `Bloom` - String + - `SignerPubkey` - String + + - `Body` - Object + - `TransactionsCount` - Number + - `Transactions` - Array + - `transactionId` - String #### Example: @@ -271,7 +307,29 @@ Get block information by block height. - **Parameters**: - **`blockHash`** (String) - **`includeTransactions`** (Boolean) -- **Returns**: Object with block details + - `true` require transaction ids list in the block + - `false` Doesn’t require transaction ids list in the block + +- **Returns**: `Object` + + - `BlockHash` - String + + - `Header` - Object + - `PreviousBlockHash` - String + - `MerkleTreeRootOfTransactions` - String + - `MerkleTreeRootOfWorldState` - String + - `Extra` - Array + - `Height` - Number + - `Time` - google.protobuf.Timestamp + - `ChainId` - String + - `Bloom` - String + - `SignerPubkey` - String + + - `Body` - Object + - `TransactionsCount` - Number + - `Transactions` - Array + - `transactionId` - String + #### Example: @@ -289,7 +347,27 @@ aelf.chain.getBlockByHeight(12, false) - **Web API Path**: `/api/blockChain/transactionResult` - **Method**: GET - **Parameters**: `transactionId` (String) -- **Returns**: Object with transaction details +- **Returns**: `Object` + + - `TransactionId` - String + - `Status` - String + - `Logs` - Array + - `Address` - String + - `Name` - String + - `Indexed` - Array + - `NonIndexed` - Number + - `Bloom` - String + - `BlockNumber` - Number + - `Transaction` - Object + - `From` - String + - `To` - String + - `RefBlockNumber` - Number + - `RefBlockPrefix` - String + - `MethodName` - String + - `Params` - Object + - `Signature` - String + - `ReadableReturnValue` - Object + - `Error` - String #### Example: @@ -310,7 +388,9 @@ aelf.chain.getTxResult(transactionId) - **`blockHash`** (String) - **`offset`** (Number) - **`limit`** (Number) -- **Returns**: Array of transaction result objects +- **Returns**: + - `Array` - The array of method descriptions: + - the transaction result object #### Example: @@ -328,7 +408,6 @@ aelf.chain.getTxResults(blockHash, 0, 2) - **Web API Path**: `/api/blockChain/transactionPoolStatus` - **Method**: GET - **Parameters**: None -- **Returns**: Object with transaction pool status ### 9. Send Transaction @@ -337,61 +416,65 @@ aelf.chain.getTxResults(blockHash, 0, 2) - **Web API Path**: `/api/blockChain/sendTransaction` - **Method**: POST - **Parameters**: `Object` (Serialized protobuf data with RawTransaction string) -- **Returns**: Transaction ID + - `RawTransaction` - String ### 10. Send Multiple Transactions - - **Web API Path**: `/api/blockChain/sendTransactions` - **Method**: POST - **Parameters**: `Object` (Serialized protobuf data with RawTransaction string) -- **Returns**: Transaction IDs + - `RawTransaction` - String ### 11. Call Read-Only Method +Call a read-only method on a contract. -- **Web API Path**: `/api/blockChain/callReadOnly` - **Method**: POST - **Parameters**: `Object` (Serialized protobuf data with RawTransaction string) + - `RawTransaction` - String - **Returns**: Method call result ### 12. Get Peers +Get peer info about the connected network nodes. -- **Web API Path**: `/api/net/peers` - **Method**: GET - **Parameters**: `withMetrics` (Boolean) -- **Returns**: Array of peer info - + - `true` with metrics + - `false` without metrics + ### 13. Add Peer +Attempts to add a node to the connected network nodes -- **Web API Path**: `/api/net/peer` - **Method**: POST -- **Parameters**: `Object` (Address string) -- **Returns**: Status - +- **Parameters**: `Object` The object with the following structure : + - `Address` - String ### 14. Remove Peer +Attempts to remove a node from the connected network nodes -- **Web API Path**: `/api/net/peer` - **Method**: DELETE - **Parameters**: `address` (String) -- **Returns**: Status -### 15. Send Multiple Transactions +### 15. Calculate Transaction Fee - **Web API Path**: `/api/blockChain/calculateTransactionFee` - **Method**: POST -- **Parameters**: `CalculateTransactionFeeInput` (Object with RawTransaction string) -- **Returns**: `CalculateTransactionFeeOutput` (Object with fee details) +- **Parameters**: `CalculateTransactionFeeInput` (Object with RawTransaction string): + - `RawTransaction` - String +- **Returns**: `CalculateTransactionFeeOutput` (Object with fee details): + - `Success` - Bool + - `TransactionFee` - Array + - `ResourceFee` - Array + #### Example @@ -405,13 +488,11 @@ aelf.chain.calculateTransactionFee(rawTransaction) ### 16. Network Info -- **Web API Path**: `/api/net/networkInfo` - **Method**: GET - **Parameters**: None - **Returns**: Network connection info - ## AElf.wallet `AElf.wallet` is a static property of `AElf`. diff --git a/docs/Developer Tools/Chain Sdk/php-skd.md b/docs/Developer Tools/Chain Sdk/php-skd.md index ee769c4a..3bf88153 100644 --- a/docs/Developer Tools/Chain Sdk/php-skd.md +++ b/docs/Developer Tools/Chain Sdk/php-skd.md @@ -2,6 +2,7 @@ sidebar_position: 5 title: PHP SDK description: PHP SDK +image: /img/Logo.aelf.svg --- # aelf-sdk.php - aelf PHP API @@ -93,7 +94,6 @@ print_r($result); ``` ## Web API ----------- You can access the Web API of your aelf node at: @@ -108,7 +108,7 @@ Before using the methods, make sure you have an instance of AElf: ```php require_once 'vendor/autoload.php'; use AElf\AElf; - +// create a new instance of AElf $url = '127.0.0.1:8000'; $aelf = new AElf($url); ``` @@ -120,11 +120,28 @@ $aelf = new AElf($url); - **Parameters**: None -- **Returns**: Array with chain status details +- **Returns**: + + - `Array` + - `ChainId` - String + - `Branches` - Array + - `NotLinkedBlocks` - Array + - `LongestChainHeight` - Integer + - `LongestChainHash` - String + - `GenesisBlockHash` - String + - `GenesisContractAddress` - String + - `LastIrreversibleBlockHash` - String + - `LastIrreversibleBlockHeight` - Integer + - `BestChainHash` - String + - `BestChainHeight` - Integer + - **Example** : ```php +// create a new instance of AElf +$aelf = new AElf($url); + $chainStatus = $aelf->getChainStatus(); print_r($chainStatus); ``` @@ -142,12 +159,14 @@ print_r($chainStatus); - **Example** : ```php +$aelf = new AElf($url); + $height = $aelf->getBlockHeight(); print($height); ``` -### 3. Get Block by Hash +### 3. getBlock - **API Path**: `/api/blockChain/block` @@ -156,11 +175,30 @@ print($height); - `block_hash` (String) - `include_transactions` (Boolean) -- **Returns**: Array with block information +- **Returns**: + + - `Array` + - `BlockHash` - String + - `Header` - Array + - `PreviousBlockHash` - String + - `MerkleTreeRootOfTransactions` - String + - `MerkleTreeRootOfWorldState` - String + - `Extra` - List + - `Height` - Integer + - `Time` - String + - `ChainId` - String + - `Bloom` - String + - `SignerPubkey` - String + - `Body` - Array + - `TransactionsCount` - Integer + - `Transactions` - Array + - `transactionId` - String - **Example** : ```php +$aelf = new AElf($url); + $block = $aelf->getBlockByHeight(1, true); $block2 = $aelf->getBlockByHash($block['BlockHash'], false); print_r($block2); @@ -176,11 +214,31 @@ print_r($block2); - `block_height` (Number) - `include_transactions` (Boolean) -- **Returns**: Array with block information +- **Returns**: + + - `Array` + - `BlockHash` - String + - `Header` - Array + - `PreviousBlockHash` - String + - `MerkleTreeRootOfTransactions` - String + - `MerkleTreeRootOfWorldState` - String + - `Extra` - List + - `Height` - Integer + - `Time` - String + - `ChainId` - String + - `Bloom` - String + - `SignerPubkey` - String + - `Body` - Array + - `TransactionsCount` - Integer + - `Transactions` - Array + - `transactionId` - String + - **Example** : ```php +$aelf = new AElf($url); + $block = $aelf->getBlockByHeight(1, true); print_r($block); ``` @@ -194,11 +252,35 @@ print_r($block); - `transactionId` (String) -- **Returns**: Object with transaction result details +- **Returns**: + + - `Object` + - `TransactionId` - String + - `Status` - String + - `Logs` - Array + - `Address` - String + - `Name` - String + - `Indexed` - Array + - `NonIndexed` - String + - `Bloom` - String + - `BlockNumber` - Integer + - `Transaction` - Array + - `From` - String + - `To` - String + - `RefBlockNumber` - Integer + - `RefBlockPrefix` - String + - `MethodName` - String + - `Params` - json + - `Signature` - String + - `transactionId` - String + - `ReadableReturnValue` - String + - `Error` - String - **Example** : ```php +$aelf = new AElf($url); + $block = $aelf->getBlockByHeight(1, true); $transactionResult = $aelf->getTransactionResult($block['Body']['Transactions'][0]); print_r($transactionResult); @@ -215,11 +297,16 @@ print_r($transactionResult); - `offset` (Number) - `limit` (Number) -- **Returns**: List of transaction result objects +- **Returns**: + + - `List` - The array of method descriptions: + - the transaction result object - **Example** : ```php +$aelf = new AElf($url); + $block = $aelf->getBlockByHeight(1, true); $transactionResults = $aelf->getTransactionResults($block['Body']); print_r($transactionResults); @@ -233,6 +320,8 @@ print_r($transactionResults); - **Example** : ```php +$aelf = new AElf($url); + $status = $aelf->getTransactionPoolStatus(); print_r($status); ``` @@ -273,6 +362,8 @@ print_r($result); - **Example** : ```php +$aelf = new AElf($url); + $paramsList = [$params1, $params2]; $rawTransactionsList = []; foreach ($paramsList as $param) { @@ -339,11 +430,16 @@ $aelf->removePeer($url); - `transaction` (Array) -- **Returns**: Array with the raw transaction hex string +- **Returns**: + + - `Array` + - `RawTransaction` - hex string bytes generated by transaction information - **Example** : ```php +$aelf = new AElf($url); + $status = $aelf->getChainStatus(); $params = base64_encode(hex2bin(hash('sha256', 'AElf.ContractNames.Consensus'))); $param = array('value' => $params); @@ -373,6 +469,8 @@ print_r($rawTransaction); - **Example** : ```php +$aelf = new AElf($url); + $rawTransaction = $aelf->createRawTransaction($transaction); $transactionId = hash('sha256', hex2bin($rawTransaction['RawTransaction'])); $sign = $aelf->getSignatureWithPrivateKey($privateKey, $transactionId); @@ -398,6 +496,8 @@ print_r($execute); - **Example** : ```php +$aelf = new AElf($url); + $rawTransaction = $aelf->createRawTransaction($transaction); $transactionId = hash('sha256', hex2bin($rawTransaction['RawTransaction'])); $sign = $aelf->getSignatureWithPrivateKey($privateKey, $transactionId); @@ -418,6 +518,8 @@ print_r($execute); - **Example** : ```php +$aelf = new AElf($url); + $block = $aelf->getBlockByHeight(1, true); $merklePath = $aelf->getMerklePathByTransactionId($block['Body']['Transactions'][0]); print_r($merklePath); @@ -434,11 +536,19 @@ print_r($merklePath); - `CalculateTransactionFeeInput` (Object) -- **Returns**: `CalculateTransactionFeeOutput (Object)` +- **Returns**: + + - `CalculateTransactionFeeOutput (Object)` + + - `Success` - bool + - `TransactionFee` - Array + - `ResourceFee` - Array - **Example** : ```php +$aelf = new AElf($url); + $calculateTransactionFeeInputParam = [ "rawTransaction" => $rawTransactionInput, ]; @@ -454,6 +564,8 @@ print_r($result); - **Example** : ```php +$aelf = new AElf($url); + print_r($aelf->getNetworkInfo()); ``` diff --git a/docs/Developer Tools/Chain Sdk/python-sdk.md b/docs/Developer Tools/Chain Sdk/python-sdk.md index f2e71d82..004196d6 100644 --- a/docs/Developer Tools/Chain Sdk/python-sdk.md +++ b/docs/Developer Tools/Chain Sdk/python-sdk.md @@ -2,6 +2,7 @@ sidebar_position: 6 title: Python SDK description: Python SDK +image: /img/Logo.aelf.svg --- # aelf-sdk.py - aelf Python API diff --git a/docs/Developer Tools/aelf-web-login.md b/docs/Developer Tools/aelf-web-login.md index 33b3f497..24bd4100 100644 --- a/docs/Developer Tools/aelf-web-login.md +++ b/docs/Developer Tools/aelf-web-login.md @@ -1,3 +1,10 @@ +--- +sidebar_position: 1 +title: Introduction +description: Introduction +image: /img/Logo.aelf.svg +--- + # Introduction **aelf-web-login**: Modular React wallet collection and components for aelf applications. diff --git a/docs/Quick Start/Develop your first aelf Smart Contract/index.md b/docs/Quick Start/Develop your first aelf Smart Contract/index.md index feb8b279..1050d49e 100644 --- a/docs/Quick Start/Develop your first aelf Smart Contract/index.md +++ b/docs/Quick Start/Develop your first aelf Smart Contract/index.md @@ -1,3 +1,10 @@ +--- +sidebar_position: 4 +title: Smart Contract Developing Demos +description: Smart Contract Developing Demos +image: /img/Logo.aelf.svg +--- + # Smart Contract Developing Demos ### Bingo Game diff --git a/docs/References/command-line-Interface/Commands.md b/docs/References/command-line-Interface/Commands.md index 1ba03ad2..8b874478 100644 --- a/docs/References/command-line-Interface/Commands.md +++ b/docs/References/command-line-Interface/Commands.md @@ -2,6 +2,7 @@ sidebar_position: 2 title: Commands description: Commands +image: /img/Logo.aelf.svg --- # Commands Overview diff --git a/docs/References/command-line-Interface/Introduction.md b/docs/References/command-line-Interface/Introduction.md index b6a113fc..b01c6ea9 100644 --- a/docs/References/command-line-Interface/Introduction.md +++ b/docs/References/command-line-Interface/Introduction.md @@ -2,6 +2,7 @@ sidebar_position: 1 title: Introduction to the CLI description: Introduction to the CLI +image: /img/Logo.aelf.svg --- # Introduction to the CLI diff --git a/docs/Resources/Browser Extension/index.md b/docs/Resources/Browser Extension/index.md index 99f7d24c..00710b0c 100644 --- a/docs/Resources/Browser Extension/index.md +++ b/docs/Resources/Browser Extension/index.md @@ -2,6 +2,7 @@ sidebar_position: 4 title: Browser Extension description: Explore Portkey wallet and other extensions +image: /img/Logo.aelf.svg --- # aelf-web-extension diff --git a/docs/Resources/DevOps/index.md b/docs/Resources/DevOps/index.md index a71ed14d..fd9bbe1f 100644 --- a/docs/Resources/DevOps/index.md +++ b/docs/Resources/DevOps/index.md @@ -2,6 +2,7 @@ sidebar_position: 5 title: DevOps description: Tools to build and deploy efficiently +image: /img/Logo.aelf.svg --- # DevOps diff --git a/docs/Resources/Wallet and Block Explorer/index.md b/docs/Resources/Wallet and Block Explorer/index.md index aa788244..b547c5b0 100644 --- a/docs/Resources/Wallet and Block Explorer/index.md +++ b/docs/Resources/Wallet and Block Explorer/index.md @@ -1,6 +1,7 @@ --- sidebar_position: 2 title: Wallet and Block Explorer +image: /img/Logo.aelf.svg --- # Wallet and Block Explorer diff --git a/docs/Tutorials/aelf-blockchain-boot-sequance.md b/docs/Tutorials/aelf-blockchain-boot-sequance.md index 7c61c897..e52a47d4 100644 --- a/docs/Tutorials/aelf-blockchain-boot-sequance.md +++ b/docs/Tutorials/aelf-blockchain-boot-sequance.md @@ -1,3 +1,10 @@ +--- +sidebar_position: 1 +title: aelf Blockchain Boot Sequence +description: aelf Blockchain Boot Sequence +image: /img/Logo.aelf.svg +--- + # aelf Blockchain Boot Sequence This guide explains how the aelf Blockchain starts from initial nodes and transitions to production nodes through elections, completing the full startup process. @@ -11,7 +18,8 @@ To begin the aelf Blockchain, you need to start at least one initial node. It’ ##### Setup Initial Nodes: - Refer to the "Getting Started" section for detailed steps. -- Use the :doc:`Running multi-nodes with Docker <../getting_started/development-environment/node>` guide to start the initial nodes. This example uses three initial nodes. + +- This example uses three initial nodes. ##### Election Time Configuration: diff --git a/docs/protocol/transactions/index.md b/docs/protocol/transactions/index.md index 26f2f7d2..32eeb0c9 100644 --- a/docs/protocol/transactions/index.md +++ b/docs/protocol/transactions/index.md @@ -1,3 +1,10 @@ +--- +sidebar_position: 4 +title: Transactions +description: Transactions +image: /img/Logo.aelf.svg +--- + # Overview Transactions play a critical role in modifying the state of the aelf blockchain through interactions with smart contracts. Here’s how transactions function: