aelf-sdk.js - AELF JavaScript API

Introduction
This is the AElf JavaScript API which connects to the Generic JSON RPC spec.
You need to run a local or remote AElf node to use this library.
Please read the ./docs for more.
Get the examples in the ./examples
directory
Installation
Script
<script src="https://unpkg.com/aelf-sdk@lastest/dist/aelf.umd.js"></script>
Npm
npm install aelf-sdk
Yarn
yarn add aelf-sdk
Library files
In our dist directory, we support different packages for different platforms, such as Node and Browser.
packages | usage |
---|
dist/aelf.cjs.js | built for node, remove node-built modules such as crypto. |
dist/aelf.umd.js | built for browser, add some node modules by webpack |
You can choose any packages based on what you need, for examples:
if you are new to FrontEnd, you can use AElf-sdk
by add a script tag in your html files.
<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
Webpack:
module.exports = {
resolve: {
alias: {
'aelf-sdk': 'aelf-sdk/dist/aelf.umd.js'
}
}
}
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': 'aelf-sdk/dist/aelf.cjs.js'
}
}
}
Rollup:
const alias = require('rollup-plugin-alias');
rollup({
plugins: [
alias({
'aelf-sdk': require.resolve('aelf-sdk/dist/aelf.cjs.js')
})
]
})
Basic usage
import AElf from 'aelf-sdk';
const aelf = new AElf(new AElf.providers.HttpProvider('https://127.0.0.1:8000'));
init contract and call methods. You can get more demos in ./examples.
await aelf.chain.contractAt(tokenContractAddress, wallet);
aelf.chain.contractAt(tokenContractAddress, wallet)
.then(result => {});
aelf.chain.contractAt(tokenContractAddress, wallet, (error, result) => {});
Additionally you can set a provider using aelf.setProvider()
import AElf from 'aelf-sdk';
const aelf = new AElf(new AElf.providers.HttpProvider('https://127.0.0.1:8000'));
aelf.setProvider(new AElf.providers.HttpProvider('https://127.0.0.1:8010'));
wallet
base on bip39.
import AElf from 'aelf-sdk';
AElf.wallet.createNewWallet();
pbjs
almost the same as protobufjs
Sometimes we have to deal with some protobuf data.
pbUtils
Some basic format methods of aelf.
For more information, please see the code in ./lib/aelf/proto.js. It is simple and easy to understand.
getRepForAddress
getAddressFromRep
getAddressObjectFromRep
getRepForHash
getHashFromHex
getHashObjectFromHex
getTransaction
getMsigTransaction
getAuthorization
getReviewer
encodeTransaction
getProposal
encodeProposal
getApproval
encodeApproval
getSideChainInfo
getBalance
encodeSideChainInfo
Transaction
Hash
Address
Authorization
Proposal
ProposalStatus
SideChainInfo
SideChainStatus
ResourceTypeBalancePair
version
import AElf from 'aelf-sdk';
AElf.version
Contributing
-
All contributions have to go into the dev-2.0 branch
-
Please follow the code style of the other files, we use 4 spaces as tabs.
Requirements
Support

About contributing
Read out contributing guide
About Version
https://semver.org/