aelf-sdk.js - AELF JavaScript API
| Branch | Tests | Coverage |
|---|---|---|
master |
1. Introduction
aelf-sdk.js for aelf is like web.js for ethereum.
aelf-sdk.js is a collection of libraries which allow you to interact with a local or remote aelf node, using a HTTP connection.
The following documentation will guide you through installing and running aelf-sdk.js, as well as providing a API reference documentation with examples.
You can get some codes in the ./examples directory
2. Getting Started
2.1 Adding aelf-sdk.js
First you need to get aelf-sdk.js into your project. This can be done using the following methods:
npm: npm install aelf-sdk
pure js: link dist/aelf.umd.js
After that you need to create a aelf instance and set a provider.
// 1.In node.js use: const AElf = require('aelf-sdk');
// 2.FrontEnd freshman, add following tag in html
// <script src="https://unpkg.com/aelf-sdk@lastest/dist/aelf.umd.js"></script>
const aelf = new AElf(new AElf.providers.HttpProvider('http://127.0.0.1:8000'));
2.2 Detail information for library files
You can skip 2.2 as 2.1 is enough now.
In our dist directory, we supply two kinds of packages for different platforms, such as Node and Browser.
| packages | usage |
|---|---|
| dist/aelf.esm.js | built as an ES Module, optimized for modern bundlers and tree-shaking. Designed for use in modern JavaScript environments like webpack, Rollup, and Vite. |
| dist/aelf.cjs.js | built for node, remove node built-in modules such as crypto. |
| dist/aelf.umd.js | built for browser, add some node built-in modules by webpack |
You can choose any packages based on your need, for examples:
if you are new to FrontEnd, you can use AElf-sdk by add a script tag in your html files.
<!-- minified version with UMD module -->
<script src="https://unpkg.com/aelf-sdk@lastest/dist/aelf.umd.js"></script>
if you want to use a bundle system such as webpack or rollup, and build your applications for Node.js and Browsers, just import the specified version of package files.
For browser usage and use UMD
ESM
// ✅ Recommended: Use "exports" to enable Tree Shaking
import wallet from 'aelf-sdk/wallet';
// ✅ Also supported: Directly import from the "src" directory
import wallet from 'aelf-sdk/src/wallet/index.js';
// ✅ Backward compatibility: Traditional import method
import AElf from 'aelf-sdk';
const { wallet } = AElf;
Webpack:
module.exports = {
// ...
resolve: {
alias: {
'aelf-sdk
Rollup:
const alias = require('rollup-plugin-alias');
rollup({
// ...
plugins: [
alias({
'aelf-sdk': require.resolve('aelf-sdk/dist/aelf.umd.js')
})
]
});
For Node.js usage and use commonjs module system
Webpack:
module.exports = {
// ...
resolve: {
alias: {
'aelf-sdk
Rollup:
const alias = require('rollup-plugin-alias');
rollup({
// ...
plugins: [
alias({
'aelf-sdk': require.resolve('aelf-sdk/dist/aelf.cjs.js')
})
]
});
3. Basic usage
3.1 Examples
You can also see full examples in ./examples;
Create a new instance of AElf, connect to an AELF chain node.
import AElf from 'aelf-sdk';
// create a new instance of AElf
const aelf = new AElf(new AElf.providers.HttpProvider('http://127.0.0.1:1235'));
Create or load a wallet with AElf.wallet
// create a new wallet
const newWallet = AElf.wallet.createNewWallet();
// load a wallet by private key
const priviteKeyWallet = AElf.wallet.getWalletByPrivateKey('xxxxxxx');
// load a wallet by mnemonic
const mnemonicWallet = AElf.wallet.getWalletByMnemonic('set kite ...');
Get a system contract address, take AElf.ContractNames.Token as an example
const tokenContractName = 'AElf.ContractNames.Token';
let tokenContractAddress;
(async () => {
// get chain status
const chainStatus = await aelf.chain.getChainStatus();
// get genesis contract address
const GenesisContractAddress = chainStatus.GenesisContractAddress;
// get genesis contract instance
const zeroContract = await aelf.chain.contractAt(GenesisContractAddress, newWallet);
// Get contract address by the read only method `GetContractAddressByName` of genesis contract
tokenContractAddress = await zeroContract.GetContractAddressByName.call(AElf.utils.sha256(tokenContractName));
})();
Get a contract instance by contract address
const wallet = AElf.wallet.createNewWallet();
let tokenContract;
// Use token contract for examples to demonstrate how to get a contract instance in different ways
// in async function
(async () => {
tokenContract = await aelf.chain.contractAt(tokenContractAddress, wallet);
})();
// promise way
aelf.chain.contractAt(tokenContractAddress, wallet).then(result => {
tokenContract = result;
});
// callback way
aelf.chain.contractAt(tokenContractAddress, wallet, (error, result) => {
if (error) throw error;
tokenContract = result;
});
How to use contract instance
A contract instance consists of several contract methods and methods can be called in two ways: read-only and send transaction.
(async () => {
// get the balance of an address, this would not send a transaction,
// or store any data on the chain, or required any transaction fee, only get the balance
// with `.call` method, `aelf-sdk` will only call read-only method
const result = await tokenContract.GetBalance.call({
symbol: 'ELF',
owner: '7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz'
});
console.log(result);
/**
{
"symbol": "ELF",
"owner": "2661mQaaPnzLCoqXPeys3Vzf2wtGM1kSrqVBgNY4JUaGBxEsX8",
"balance": "1000000000000"
}*/
// with no `.call`, `aelf-sdk` will sign and send a transaction to the chain, and return a transaction id.
// make sure you have enough transaction fee `ELF` in your wallet
const transactionId = await tokenContract.Transfer({
symbol: 'ELF',
to: '7s4XoUHfPuqoZAwnTV7pHWZAaivMiL8aZrDSnY9brE1woa8vz',
amount: '1000000000',
memo: 'transfer in demo'
});
console.log(transactionId);
/**
{
"TransactionId": "123123"
}
*/
})();
Change the node endpoint by using aelf.setProvider
import AElf from 'aelf-sdk';
const aelf = new AElf(new AElf.providers.HttpProvider('http://127.0.0.1:1235'));
aelf.setProvider(new AElf.providers.HttpProvider('http://127.0.0.1:8000'));
3.2 Web API
You can see how the Web Api of the node works in {chainAddress}/swagger/index.html
tip: for an example, my local address: '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
The usage of these methods is based on the AElf instance, so if you don't have one please create it:
import AElf from 'aelf-sdk';
// create a new instance of AElf, change the URL if needed
const aelf = new AElf(new AElf.providers.HttpProvider('http://127.0.0.1:1235'));
getChainStatus
Get the current status of the block chain.
Web API path
/api/blockChain/chainStatus
Parameters
Empty
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
aelf.chain.getChainStatus().then(res => {
console.log(res);
});
getContractFileDescriptorSet
Get the protobuf definitions related to a contract
Web API path
/api/blockChain/contractFileDescriptorSet
Parameters
contractAddress - String address of a contract
Returns
String
Example
aelf.chain.getContractFileDescriptorSet(contractAddress).then(res => {
console.log(res);
});
getBlockHeight
Get current best height of the chain.
Web API path
/api/blockChain/blockHeight
Parameters
Empty
Returns
Number
Example
aelf.chain.getBlockHeight().then(res => {
console.log(res);
});
getBlock
Get block information by block hash.
Web API path
/api/blockChain/block
Parameters
blockHash - String
includeTransactions - Boolean :
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
aelf.chain.getBlock(blockHash, false).then(res => {
console.log(res);
});
getBlockByHeight
Web API path
/api/blockChain/blockByHeight
Get block information by block height.
Parameters
blockHeight - Number
includeTransactions - Boolean :
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
aelf.chain.getBlockByHeight(12, false).then(res => {
console.log(res);
});
getTxResult
Get the result of a transaction
Web API path
/api/blockChain/transactionResult
Parameters
transactionId - String
Returns
Object
TransactionId - String
Status - String
Logs - Array
Address - String
Name - String
Indexed - Array
NonIndexed - String
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
aelf.chain.getTxResult(transactionId).then(res => {
console.log(res);
});
getTxResults
Get multiple transaction results in a block
Web API path
/api/blockChain/transactionResults
Parameters
blockHash - String
offset - Number
limit - Number
Returns
Array - The array of method descriptions:
- the transaction result object
Example
aelf.chain.getTxResults(blockHash, 0, 2).then(res => {
console.log(res);
});
getTransactionPoolStatus
Get the transaction pool status.
Web API path
/api/blockChain/transactionPoolStatus
Parameters
Empty
sendTransaction
Broadcast a transaction
Web API path
/api/blockChain/sendTransaction
POST
Parameters
Object - Serialization of data into protobuf data, The object with the following structure :
RawTransaction - String :
usually developers don't need to use this function directly, just get a contract method and send transaction by call contract method:
sendTransactions
Broadcast multiple transactions
POST
Parameters
Object - The object with the following structure :
RawTransaction - String
calculateTransactionFee
Estimate transaction fee
Web API path
/api/blockChain/calculateTransactionFee
POST
Parameters
Object - The object with the following structure :
RawTransaction - String
callReadOnly
Call a read-only method on a contract.
POST
Parameters
Object - The object with the following structure :
RawTransaction - String
getPeers
Get peer info about the connected network nodes
addPeer
Attempts to add a node to the connected network nodes
you need to create a aelf authorization instance and set a provider
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('UseName', 'Password')
})
);
Example
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('aelf', '12345678')
})
);
aelf.chain.addPeer('192.168.11.140:6801').then(res => {
console.log(res);
});
removePeer
Attempts to remove a node from the connected network nodes
you need to create a aelf authorization instance and set a provider
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('UseName', 'Password')
})
);
Example
const aelf = new AElf(
new AElf.providers.HttpProvider('http://127.0.0.1:8000', 8000, {
Authorization: AElf.utils.getAuthorization('aelf', '12345678')
})
);
aelf.chain.removePeer('192.168.11.140:6801').then(res => {
console.log(res);
});
networkInfo
Get information about the node’s connection to the network
3.3 AElf.wallet
AElf.wallet is a static property of AElf.
Use the api to see detailed results
createNewWallet
Returns
Object
mnemonic - String: mnemonic
BIP44Path - String: m/purpose'/coin_type'/account'/change/address_index
childWallet - Object: HD Wallet
keyPair - String: The EC key pair generated by elliptic
privateKey - String: private Key
address - String: address
Example
import AElf from 'aelf-sdk';
const wallet = AElf.wallet.createNewWallet();
getWalletByMnemonic
Parameters
mnemonic - String : wallet's mnemonic
Returns
Object: Complete wallet object.
Example
const wallet = AElf.wallet.getWalletByMnemonic(mnemonic);
getWalletByPrivateKey
Parameters
privateKey: String : wallet's private key
Returns
Object: Complete wallet object, with empty mnemonic
Example
const wallet = AElf.wallet.getWalletByPrivateKey(privateKey);
signTransaction
Use wallet keypair to sign a transaction
Parameters
rawTxn - String
keyPair - String
Returns
Object: The object with the following structure :
Example
const result = AElf.wallet.signTransaction(rawTxn, keyPair);
AESEncrypt
Encrypt a string by aes algorithm
Parameters
input - String
password - String
Returns
String
AESDecrypt
Decrypt by aes algorithm
Parameters
input - String
password - String
Returns
String
3.4 AElf.pbjs
Simple example in how to use aelf.pbjs;
The reference to protobuf.js, read the documentation to see how to use.
3.5 AElf.pbUtils
Some basic format methods about proto for aelf.
For more information, please see the code in src/util/proto.js. It is simple and easy to understand.
3.6 AElf.utils
Some methods for aelf.
For more information, please see the code in src/util/utils.js. It is simple and easy to understand.
3.6.1 Check address
const AElf = require('aelf-sdk');
const { base58 } = AElf.utils;
base58.decode('$addresss'); // throw error if invalid
3.7 AElf.version
import AElf from 'aelf-sdk';
AElf.version; // eg. 3.2.23
3.8 Requirements
3.9 Support

4. Building
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
4.1 Building (webpack)
Build the web3.js package:
yarn run build
4.2 Testing (jest)
yarn run test
Commit code will run test and lint automatically, and show the test result in readme.md, please make sure all test cases passed.
4.3 About contributing
Read out contributing guide
5. About Version
: 'aelf-sdk/dist/aelf.umd.js'
}
}
};
Rollup:
__CODE_BLOCK_4__
For Node.js usage and use commonjs module system
Webpack:
__CODE_BLOCK_5__
Rollup:
__CODE_BLOCK_6__
3. Basic usage
3.1 Examples
You can also see full examples in ./examples;
Create a new instance of AElf, connect to an AELF chain node.
__CODE_BLOCK_7__
Create or load a wallet with __INLINE_CODE_4__
__CODE_BLOCK_8__
Get a system contract address, take __INLINE_CODE_5__ as an example
__CODE_BLOCK_9__
Get a contract instance by contract address
__CODE_BLOCK_10__
How to use contract instance
A contract instance consists of several contract methods and methods can be called in two ways: read-only and send transaction.
__CODE_BLOCK_11__
Change the node endpoint by using __INLINE_CODE_6__
__CODE_BLOCK_12__
3.2 Web API
You can see how the Web Api of the node works in __INLINE_CODE_7__
tip: for an example, my local address: 'http://127.0.0.1:1235/swagger/index.html'
parameters and returns based on the URL: __INLINE_CODE_8__
The usage of these methods is based on the AElf instance, so if you don't have one please create it:
__CODE_BLOCK_13__
getChainStatus
Get the current status of the block chain.
Web API path
__INLINE_CODE_9__
Parameters
Empty
Returns
__INLINE_CODE_10__
- __INLINE_CODE_11__
- __INLINE_CODE_12__
- __INLINE_CODE_13__
- __INLINE_CODE_14__
- __INLINE_CODE_15__
- __INLINE_CODE_16__
- __INLINE_CODE_17__
- __INLINE_CODE_18__
- __INLINE_CODE_19__
- __INLINE_CODE_20__
- __INLINE_CODE_21__
Example
__CODE_BLOCK_14__
getContractFileDescriptorSet
Get the protobuf definitions related to a contract
Web API path
__INLINE_CODE_22__
Parameters
- __INLINE_CODE_23__ address of a contract
Returns
__INLINE_CODE_24__
Example
__CODE_BLOCK_15__
getBlockHeight
Get current best height of the chain.
Web API path
__INLINE_CODE_25__
Parameters
Empty
Returns
__INLINE_CODE_26__
Example
__CODE_BLOCK_16__
getBlock
Get block information by block hash.
Web API path
__INLINE_CODE_27__
Parameters
- __INLINE_CODE_28__
- __INLINE_CODE_29__ :
- __INLINE_CODE_30__ require transaction ids list in the block
- __INLINE_CODE_31__ Doesn't require transaction ids list in the block
Returns
__INLINE_CODE_32__
- __INLINE_CODE_33__
- __INLINE_CODE_34__
- __INLINE_CODE_35__
- __INLINE_CODE_36__
- __INLINE_CODE_37__
- __INLINE_CODE_38__
- __INLINE_CODE_39__
- __INLINE_CODE_40__
- __INLINE_CODE_41__
- __INLINE_CODE_42__
- __INLINE_CODE_43__
- __INLINE_CODE_44__
- __INLINE_CODE_45__
- __INLINE_CODE_46__
- __INLINE_CODE_47__
Example
__CODE_BLOCK_17__
getBlockByHeight
Web API path
__INLINE_CODE_48__
Get block information by block height.
Parameters
- __INLINE_CODE_49__
- __INLINE_CODE_50__ :
- __INLINE_CODE_51__ require transaction ids list in the block
- __INLINE_CODE_52__ Doesn't require transaction ids list in the block
Returns
__INLINE_CODE_53__
- __INLINE_CODE_54__
- __INLINE_CODE_55__
- __INLINE_CODE_56__
- __INLINE_CODE_57__
- __INLINE_CODE_58__
- __INLINE_CODE_59__
- __INLINE_CODE_60__
- __INLINE_CODE_61__
- __INLINE_CODE_62__
- __INLINE_CODE_63__
- __INLINE_CODE_64__
- __INLINE_CODE_65__
- __INLINE_CODE_66__
- __INLINE_CODE_67__
- __INLINE_CODE_68__
Example
__CODE_BLOCK_18__
getTxResult
Get the result of a transaction
Web API path
__INLINE_CODE_69__
Parameters
- __INLINE_CODE_70__
Returns
__INLINE_CODE_71__
- __INLINE_CODE_72__
- __INLINE_CODE_73__
- __INLINE_CODE_74__
- __INLINE_CODE_75__
- __INLINE_CODE_76__
- __INLINE_CODE_77__
- __INLINE_CODE_78__
- __INLINE_CODE_79__
- __INLINE_CODE_80__
- __INLINE_CODE_81__
- __INLINE_CODE_82__
- __INLINE_CODE_83__
- __INLINE_CODE_84__
- __INLINE_CODE_85__
- __INLINE_CODE_86__
- __INLINE_CODE_87__
- __INLINE_CODE_88__
- __INLINE_CODE_89__
- __INLINE_CODE_90__
Example
__CODE_BLOCK_19__
getTxResults
Get multiple transaction results in a block
Web API path
__INLINE_CODE_91__
Parameters
- __INLINE_CODE_92__
- __INLINE_CODE_93__
- __INLINE_CODE_94__
Returns
__INLINE_CODE_95__ - The array of method descriptions:
- the transaction result object
Example
__CODE_BLOCK_20__
getTransactionPoolStatus
Get the transaction pool status.
Web API path
__INLINE_CODE_96__
Parameters
Empty
sendTransaction
Broadcast a transaction
Web API path
__INLINE_CODE_97__
POST
Parameters
__INLINE_CODE_98__ - Serialization of data into protobuf data, The object with the following structure :
- __INLINE_CODE_99__ :
usually developers don't need to use this function directly, just get a contract method and send transaction by call contract method:
sendTransactions
Broadcast multiple transactions
POST
Parameters
__INLINE_CODE_100__ - The object with the following structure :
- __INLINE_CODE_101__
calculateTransactionFee
Estimate transaction fee
Web API path
__INLINE_CODE_102__
POST
Parameters
__INLINE_CODE_103__ - The object with the following structure :
- __INLINE_CODE_104__
callReadOnly
Call a read-only method on a contract.
POST
Parameters
__INLINE_CODE_105__ - The object with the following structure :
- __INLINE_CODE_106__
getPeers
Get peer info about the connected network nodes
addPeer
Attempts to add a node to the connected network nodes
you need to create a aelf authorization instance and set a provider
__CODE_BLOCK_21__
Example
__CODE_BLOCK_22__
removePeer
Attempts to remove a node from the connected network nodes
you need to create a aelf authorization instance and set a provider
__CODE_BLOCK_23__
Example
__CODE_BLOCK_24__
networkInfo
Get information about the node’s connection to the network
3.3 AElf.wallet
__INLINE_CODE_107__ is a static property of __INLINE_CODE_108__.
Use the api to see detailed results
createNewWallet
Returns
__INLINE_CODE_109__
- __INLINE_CODE_110__: mnemonic
- __INLINE_CODE_111__: m/purpose'/coin_type'/account'/change/address_index
- __INLINE_CODE_112__: HD Wallet
- __INLINE_CODE_113__: The EC key pair generated by elliptic
- __INLINE_CODE_114__: private Key
- __INLINE_CODE_115__: address
Example
__CODE_BLOCK_25__
getWalletByMnemonic
Parameters
- __INLINE_CODE_116__ : wallet's mnemonic
Returns
__INLINE_CODE_117__: Complete wallet object.
Example
__CODE_BLOCK_26__
getWalletByPrivateKey
Parameters
- __INLINE_CODE_118__ : wallet's private key
Returns
__INLINE_CODE_119__: Complete wallet object, with empty mnemonic
Example
__CODE_BLOCK_27__
signTransaction
Use wallet __INLINE_CODE_120__ to sign a transaction
Parameters
- __INLINE_CODE_121__
- __INLINE_CODE_122__
Returns
__INLINE_CODE_123__: The object with the following structure :
Example
__CODE_BLOCK_28__
AESEncrypt
Encrypt a string by aes algorithm
Parameters
- __INLINE_CODE_124__
- __INLINE_CODE_125__
Returns
__INLINE_CODE_126__
AESDecrypt
Decrypt by aes algorithm
Parameters
- __INLINE_CODE_127__
- __INLINE_CODE_128__
Returns
__INLINE_CODE_129__
3.4 AElf.pbjs
Simple example in how to use aelf.pbjs;
The reference to protobuf.js, read the documentation to see how to use.
3.5 AElf.pbUtils
Some basic format methods about proto for aelf.
For more information, please see the code in src/util/proto.js. It is simple and easy to understand.
3.6 AElf.utils
Some methods for aelf.
For more information, please see the code in src/util/utils.js. It is simple and easy to understand.
3.6.1 Check address
__CODE_BLOCK_29__
3.7 AElf.version
__CODE_BLOCK_30__
3.8 Requirements
3.9 Support

4. Building
__CODE_BLOCK_31__
4.1 Building (webpack)
Build the web3.js package:
__CODE_BLOCK_32__
4.2 Testing (jest)
__CODE_BLOCK_33__
Commit code will run test and lint automatically, and show the test result in readme.md, please make sure all test cases passed.
4.3 About contributing
Read out contributing guide
5. About Version
: 'aelf-sdk/dist/aelf.cjs.js'
}
}
};
Rollup:
__CODE_BLOCK_6__3. Basic usage
3.1 Examples
You can also see full examples in ./examples;
Create a new instance of AElf, connect to an AELF chain node.
__CODE_BLOCK_7__Create or load a wallet with __INLINE_CODE_4__
__CODE_BLOCK_8__Get a system contract address, take __INLINE_CODE_5__ as an example
__CODE_BLOCK_9__Get a contract instance by contract address
__CODE_BLOCK_10__How to use contract instance
A contract instance consists of several contract methods and methods can be called in two ways: read-only and send transaction.
__CODE_BLOCK_11__Change the node endpoint by using __INLINE_CODE_6__
__CODE_BLOCK_12__
3.2 Web API
You can see how the Web Api of the node works in __INLINE_CODE_7__ tip: for an example, my local address: 'http://127.0.0.1:1235/swagger/index.html'
parameters and returns based on the URL: __INLINE_CODE_8__
The usage of these methods is based on the AElf instance, so if you don't have one please create it:
__CODE_BLOCK_13__getChainStatus
Get the current status of the block chain.
Web API path
__INLINE_CODE_9__
Parameters
Empty
Returns
__INLINE_CODE_10__
- __INLINE_CODE_11__
- __INLINE_CODE_12__
- __INLINE_CODE_13__
- __INLINE_CODE_14__
- __INLINE_CODE_15__
- __INLINE_CODE_16__
- __INLINE_CODE_17__
- __INLINE_CODE_18__
- __INLINE_CODE_19__
- __INLINE_CODE_20__
- __INLINE_CODE_21__
Example
__CODE_BLOCK_14__getContractFileDescriptorSet
Get the protobuf definitions related to a contract
Web API path
__INLINE_CODE_22__
Parameters
- __INLINE_CODE_23__ address of a contract
Returns
__INLINE_CODE_24__
Example
__CODE_BLOCK_15__getBlockHeight
Get current best height of the chain.
Web API path
__INLINE_CODE_25__
Parameters
Empty
Returns
__INLINE_CODE_26__
Example
__CODE_BLOCK_16__getBlock
Get block information by block hash.
Web API path
__INLINE_CODE_27__
Parameters
- __INLINE_CODE_28__
- __INLINE_CODE_29__ :
- __INLINE_CODE_30__ require transaction ids list in the block
- __INLINE_CODE_31__ Doesn't require transaction ids list in the block
Returns
__INLINE_CODE_32__
- __INLINE_CODE_33__
- __INLINE_CODE_34__
- __INLINE_CODE_35__
- __INLINE_CODE_36__
- __INLINE_CODE_37__
- __INLINE_CODE_38__
- __INLINE_CODE_39__
- __INLINE_CODE_40__
- __INLINE_CODE_41__
- __INLINE_CODE_42__
- __INLINE_CODE_43__
- __INLINE_CODE_44__
- __INLINE_CODE_45__
- __INLINE_CODE_46__
- __INLINE_CODE_47__
Example
__CODE_BLOCK_17__getBlockByHeight
Web API path
__INLINE_CODE_48__
Get block information by block height.
Parameters
- __INLINE_CODE_49__
- __INLINE_CODE_50__ :
- __INLINE_CODE_51__ require transaction ids list in the block
- __INLINE_CODE_52__ Doesn't require transaction ids list in the block
Returns
__INLINE_CODE_53__
- __INLINE_CODE_54__
- __INLINE_CODE_55__
- __INLINE_CODE_56__
- __INLINE_CODE_57__
- __INLINE_CODE_58__
- __INLINE_CODE_59__
- __INLINE_CODE_60__
- __INLINE_CODE_61__
- __INLINE_CODE_62__
- __INLINE_CODE_63__
- __INLINE_CODE_64__
- __INLINE_CODE_65__
- __INLINE_CODE_66__
- __INLINE_CODE_67__
- __INLINE_CODE_68__
Example
__CODE_BLOCK_18__getTxResult
Get the result of a transaction
Web API path
__INLINE_CODE_69__
Parameters
- __INLINE_CODE_70__
Returns
__INLINE_CODE_71__
- __INLINE_CODE_72__
- __INLINE_CODE_73__
- __INLINE_CODE_74__
- __INLINE_CODE_75__
- __INLINE_CODE_76__
- __INLINE_CODE_77__
- __INLINE_CODE_78__
- __INLINE_CODE_79__
- __INLINE_CODE_80__
- __INLINE_CODE_81__
- __INLINE_CODE_82__
- __INLINE_CODE_83__
- __INLINE_CODE_84__
- __INLINE_CODE_85__
- __INLINE_CODE_86__
- __INLINE_CODE_87__
- __INLINE_CODE_88__
- __INLINE_CODE_89__
- __INLINE_CODE_90__
Example
__CODE_BLOCK_19__getTxResults
Get multiple transaction results in a block
Web API path
__INLINE_CODE_91__
Parameters
- __INLINE_CODE_92__
- __INLINE_CODE_93__
- __INLINE_CODE_94__
Returns __INLINE_CODE_95__ - The array of method descriptions:
- the transaction result object
Example
__CODE_BLOCK_20__getTransactionPoolStatus
Get the transaction pool status.
Web API path
__INLINE_CODE_96__
Parameters
Empty
sendTransaction
Broadcast a transaction
Web API path
__INLINE_CODE_97__
POST
Parameters
__INLINE_CODE_98__ - Serialization of data into protobuf data, The object with the following structure :
- __INLINE_CODE_99__ :
usually developers don't need to use this function directly, just get a contract method and send transaction by call contract method:
sendTransactions
Broadcast multiple transactions
POST
Parameters
__INLINE_CODE_100__ - The object with the following structure :
- __INLINE_CODE_101__
calculateTransactionFee
Estimate transaction fee
Web API path
__INLINE_CODE_102__
POST
Parameters
__INLINE_CODE_103__ - The object with the following structure :
- __INLINE_CODE_104__
callReadOnly
Call a read-only method on a contract.
POST
Parameters
__INLINE_CODE_105__ - The object with the following structure :
- __INLINE_CODE_106__
getPeers
Get peer info about the connected network nodes
addPeer
Attempts to add a node to the connected network nodes
you need to create a aelf authorization instance and set a provider
__CODE_BLOCK_21__Example
__CODE_BLOCK_22__removePeer
Attempts to remove a node from the connected network nodes
you need to create a aelf authorization instance and set a provider
__CODE_BLOCK_23__Example
__CODE_BLOCK_24__networkInfo
Get information about the node’s connection to the network
3.3 AElf.wallet
__INLINE_CODE_107__ is a static property of __INLINE_CODE_108__.
Use the api to see detailed results
createNewWallet
Returns
__INLINE_CODE_109__
- __INLINE_CODE_110__: mnemonic
- __INLINE_CODE_111__: m/purpose'/coin_type'/account'/change/address_index
- __INLINE_CODE_112__: HD Wallet
- __INLINE_CODE_113__: The EC key pair generated by elliptic
- __INLINE_CODE_114__: private Key
- __INLINE_CODE_115__: address
Example
__CODE_BLOCK_25__getWalletByMnemonic
Parameters
- __INLINE_CODE_116__ : wallet's mnemonic
Returns
__INLINE_CODE_117__: Complete wallet object.
Example
__CODE_BLOCK_26__getWalletByPrivateKey
Parameters
- __INLINE_CODE_118__ : wallet's private key
Returns
__INLINE_CODE_119__: Complete wallet object, with empty mnemonic
Example
__CODE_BLOCK_27__signTransaction
Use wallet __INLINE_CODE_120__ to sign a transaction
Parameters
- __INLINE_CODE_121__
- __INLINE_CODE_122__
Returns
__INLINE_CODE_123__: The object with the following structure :
Example
__CODE_BLOCK_28__AESEncrypt
Encrypt a string by aes algorithm
Parameters
- __INLINE_CODE_124__
- __INLINE_CODE_125__
Returns
__INLINE_CODE_126__
AESDecrypt
Decrypt by aes algorithm
Parameters
- __INLINE_CODE_127__
- __INLINE_CODE_128__
Returns
__INLINE_CODE_129__
3.4 AElf.pbjs
Simple example in how to use aelf.pbjs;
The reference to protobuf.js, read the documentation to see how to use.
3.5 AElf.pbUtils
Some basic format methods about proto for aelf.
For more information, please see the code in src/util/proto.js. It is simple and easy to understand.
3.6 AElf.utils
Some methods for aelf.
For more information, please see the code in src/util/utils.js. It is simple and easy to understand.
3.6.1 Check address
__CODE_BLOCK_29__3.7 AElf.version
__CODE_BLOCK_30__3.8 Requirements
3.9 Support
4. Building
__CODE_BLOCK_31__4.1 Building (webpack)
Build the web3.js package:
__CODE_BLOCK_32__4.2 Testing (jest)
__CODE_BLOCK_33__Commit code will run test and lint automatically, and show the test result in readme.md, please make sure all test cases passed.
4.3 About contributing
Read out contributing guide
5. About Version
: 'aelf-sdk/dist/aelf.umd.js' } } };Rollup:
__CODE_BLOCK_4__For Node.js usage and use commonjs module system
Webpack:
__CODE_BLOCK_5__Rollup:
__CODE_BLOCK_6__3. Basic usage
3.1 Examples
You can also see full examples in ./examples;
Create a new instance of AElf, connect to an AELF chain node.
__CODE_BLOCK_7__Create or load a wallet with __INLINE_CODE_4__
__CODE_BLOCK_8__Get a system contract address, take __INLINE_CODE_5__ as an example
__CODE_BLOCK_9__Get a contract instance by contract address
__CODE_BLOCK_10__How to use contract instance
A contract instance consists of several contract methods and methods can be called in two ways: read-only and send transaction.
__CODE_BLOCK_11__Change the node endpoint by using __INLINE_CODE_6__
__CODE_BLOCK_12__
3.2 Web API
You can see how the Web Api of the node works in __INLINE_CODE_7__ tip: for an example, my local address: 'http://127.0.0.1:1235/swagger/index.html'
parameters and returns based on the URL: __INLINE_CODE_8__
The usage of these methods is based on the AElf instance, so if you don't have one please create it:
__CODE_BLOCK_13__getChainStatus
Get the current status of the block chain.
Web API path
__INLINE_CODE_9__
Parameters
Empty
Returns
__INLINE_CODE_10__
- __INLINE_CODE_11__
- __INLINE_CODE_12__
- __INLINE_CODE_13__
- __INLINE_CODE_14__
- __INLINE_CODE_15__
- __INLINE_CODE_16__
- __INLINE_CODE_17__
- __INLINE_CODE_18__
- __INLINE_CODE_19__
- __INLINE_CODE_20__
- __INLINE_CODE_21__
Example
__CODE_BLOCK_14__getContractFileDescriptorSet
Get the protobuf definitions related to a contract
Web API path
__INLINE_CODE_22__
Parameters
- __INLINE_CODE_23__ address of a contract
Returns
__INLINE_CODE_24__
Example
__CODE_BLOCK_15__getBlockHeight
Get current best height of the chain.
Web API path
__INLINE_CODE_25__
Parameters
Empty
Returns
__INLINE_CODE_26__
Example
__CODE_BLOCK_16__getBlock
Get block information by block hash.
Web API path
__INLINE_CODE_27__
Parameters
- __INLINE_CODE_28__
- __INLINE_CODE_29__ :
- __INLINE_CODE_30__ require transaction ids list in the block
- __INLINE_CODE_31__ Doesn't require transaction ids list in the block
Returns
__INLINE_CODE_32__
- __INLINE_CODE_33__
- __INLINE_CODE_34__
- __INLINE_CODE_35__
- __INLINE_CODE_36__
- __INLINE_CODE_37__
- __INLINE_CODE_38__
- __INLINE_CODE_39__
- __INLINE_CODE_40__
- __INLINE_CODE_41__
- __INLINE_CODE_42__
- __INLINE_CODE_43__
- __INLINE_CODE_44__
- __INLINE_CODE_45__
- __INLINE_CODE_46__
- __INLINE_CODE_47__
Example
__CODE_BLOCK_17__getBlockByHeight
Web API path
__INLINE_CODE_48__
Get block information by block height.
Parameters
- __INLINE_CODE_49__
- __INLINE_CODE_50__ :
- __INLINE_CODE_51__ require transaction ids list in the block
- __INLINE_CODE_52__ Doesn't require transaction ids list in the block
Returns
__INLINE_CODE_53__
- __INLINE_CODE_54__
- __INLINE_CODE_55__
- __INLINE_CODE_56__
- __INLINE_CODE_57__
- __INLINE_CODE_58__
- __INLINE_CODE_59__
- __INLINE_CODE_60__
- __INLINE_CODE_61__
- __INLINE_CODE_62__
- __INLINE_CODE_63__
- __INLINE_CODE_64__
- __INLINE_CODE_65__
- __INLINE_CODE_66__
- __INLINE_CODE_67__
- __INLINE_CODE_68__
Example
__CODE_BLOCK_18__getTxResult
Get the result of a transaction
Web API path
__INLINE_CODE_69__
Parameters
- __INLINE_CODE_70__
Returns
__INLINE_CODE_71__
- __INLINE_CODE_72__
- __INLINE_CODE_73__
- __INLINE_CODE_74__
- __INLINE_CODE_75__
- __INLINE_CODE_76__
- __INLINE_CODE_77__
- __INLINE_CODE_78__
- __INLINE_CODE_79__
- __INLINE_CODE_80__
- __INLINE_CODE_81__
- __INLINE_CODE_82__
- __INLINE_CODE_83__
- __INLINE_CODE_84__
- __INLINE_CODE_85__
- __INLINE_CODE_86__
- __INLINE_CODE_87__
- __INLINE_CODE_88__
- __INLINE_CODE_89__
- __INLINE_CODE_90__
Example
__CODE_BLOCK_19__getTxResults
Get multiple transaction results in a block
Web API path
__INLINE_CODE_91__
Parameters
- __INLINE_CODE_92__
- __INLINE_CODE_93__
- __INLINE_CODE_94__
Returns __INLINE_CODE_95__ - The array of method descriptions:
- the transaction result object
Example
__CODE_BLOCK_20__getTransactionPoolStatus
Get the transaction pool status.
Web API path
__INLINE_CODE_96__
Parameters
Empty
sendTransaction
Broadcast a transaction
Web API path
__INLINE_CODE_97__
POST
Parameters
__INLINE_CODE_98__ - Serialization of data into protobuf data, The object with the following structure :
- __INLINE_CODE_99__ :
usually developers don't need to use this function directly, just get a contract method and send transaction by call contract method:
sendTransactions
Broadcast multiple transactions
POST
Parameters
__INLINE_CODE_100__ - The object with the following structure :
- __INLINE_CODE_101__
calculateTransactionFee
Estimate transaction fee
Web API path
__INLINE_CODE_102__
POST
Parameters
__INLINE_CODE_103__ - The object with the following structure :
- __INLINE_CODE_104__
callReadOnly
Call a read-only method on a contract.
POST
Parameters
__INLINE_CODE_105__ - The object with the following structure :
- __INLINE_CODE_106__
getPeers
Get peer info about the connected network nodes
addPeer
Attempts to add a node to the connected network nodes
you need to create a aelf authorization instance and set a provider
__CODE_BLOCK_21__Example
__CODE_BLOCK_22__removePeer
Attempts to remove a node from the connected network nodes
you need to create a aelf authorization instance and set a provider
__CODE_BLOCK_23__Example
__CODE_BLOCK_24__networkInfo
Get information about the node’s connection to the network
3.3 AElf.wallet
__INLINE_CODE_107__ is a static property of __INLINE_CODE_108__.
Use the api to see detailed results
createNewWallet
Returns
__INLINE_CODE_109__
- __INLINE_CODE_110__: mnemonic
- __INLINE_CODE_111__: m/purpose'/coin_type'/account'/change/address_index
- __INLINE_CODE_112__: HD Wallet
- __INLINE_CODE_113__: The EC key pair generated by elliptic
- __INLINE_CODE_114__: private Key
- __INLINE_CODE_115__: address
Example
__CODE_BLOCK_25__getWalletByMnemonic
Parameters
- __INLINE_CODE_116__ : wallet's mnemonic
Returns
__INLINE_CODE_117__: Complete wallet object.
Example
__CODE_BLOCK_26__getWalletByPrivateKey
Parameters
- __INLINE_CODE_118__ : wallet's private key
Returns
__INLINE_CODE_119__: Complete wallet object, with empty mnemonic
Example
__CODE_BLOCK_27__signTransaction
Use wallet __INLINE_CODE_120__ to sign a transaction
Parameters
- __INLINE_CODE_121__
- __INLINE_CODE_122__
Returns
__INLINE_CODE_123__: The object with the following structure :
Example
__CODE_BLOCK_28__AESEncrypt
Encrypt a string by aes algorithm
Parameters
- __INLINE_CODE_124__
- __INLINE_CODE_125__
Returns
__INLINE_CODE_126__
AESDecrypt
Decrypt by aes algorithm
Parameters
- __INLINE_CODE_127__
- __INLINE_CODE_128__
Returns
__INLINE_CODE_129__
3.4 AElf.pbjs
Simple example in how to use aelf.pbjs;
The reference to protobuf.js, read the documentation to see how to use.
3.5 AElf.pbUtils
Some basic format methods about proto for aelf.
For more information, please see the code in src/util/proto.js. It is simple and easy to understand.
3.6 AElf.utils
Some methods for aelf.
For more information, please see the code in src/util/utils.js. It is simple and easy to understand.
3.6.1 Check address
__CODE_BLOCK_29__3.7 AElf.version
__CODE_BLOCK_30__3.8 Requirements
3.9 Support
4. Building
__CODE_BLOCK_31__4.1 Building (webpack)
Build the web3.js package:
__CODE_BLOCK_32__4.2 Testing (jest)
__CODE_BLOCK_33__Commit code will run test and lint automatically, and show the test result in readme.md, please make sure all test cases passed.
4.3 About contributing
Read out contributing guide