@makkii/app-aion
Aion application client. This library uses some third-party service:
- Web3 JsonRPC - you can pass in jsonrpc in AionApiClient Constructor
- Explorer Api - we use https://mainnet-api.theoan.com to get transaction history, token history.
- Transaction Explorer - we use https://mainnet.theoan.com/#/transaction/
txHash
to show transaction detail page. - Remote Api - we setup our own server to provide token list and icons.
Installation
npm install @makkii/app-aion
Usage
import { AionApiClient, AionKeystoreClient, AionLocalSigner } from '@makkii/app-aion';
const api_client = new AionApiClient({
network: 'mainnet',
jsonrpc: '***'
});
api_client.getBalance('0x...')
.then(console.log)
.catch(error=>console.log(error));
const keystore_client = new AionKeystoreClient();
api_client.buildTransaction(
'0x...', // from address
'0x...', // to address
0, // amount
{
gasPrice: 10,
gasLimit: 21000,
isTokenTransfer: false
}
).then(function(unsignedTx) {
keystore_client.signTransaction(unsignedTx, new AionLocalSigner(), {
private_key: '***'
}).then(function(signedTx) {
console.log(signedTx);
});
});
API
Table of Contents
IAionConfig
Aion configuration interface
network
Network name
Type: ("mainnet"
| "amity"
)
jsonrpc
Json RPC endpoint
Type: string
explorer_api
api endpoint that used to query transaction information
Type: string
explorer
transaction page base url
Type: string
remote_api
app server endpoint that provides token, icons, etc.
Type: string
AionKeystoreClient
Aion keystore client that implements IsingleKeystoreClient interface
getAccountFromMnemonic
Get account from mnemonic
Parameters
Returns any account object: { private_key: '', public_key: '', address: '', index: '' }
recoverKeyPairByPrivateKey
Recover key pair by private key
Parameters
-
priKey
string -
privKey
private key
Returns any key pair object: { private_key: '', public_key: '', address: '' }
recoverKeyPairByKeyFile
Recover key pair by key file
Parameters
Returns any key pair object: { private_key: '', public_key: '', address: '' }
validatePrivateKey
Check if private key is valid
Parameters
Returns any if private key is valid
validateAddress
Check if address is valid
Parameters
-
address
string address to be validated
AionLocalSigner
Aion's signer using private key, implements IkeystoreSigner.
signTransaction
Sign transaction
Parameters
-
tx
AionUnsignedTx AionUnsginedTx transaction object to sign. -
params
{private_key: string} parameters object, example: { private_key: '' }}
Returns Promise<string> transaction hash string
AionUnsignedTx
Aion unsigned transaction interface
- to: string;
- from: string;
- nonce: string;
- value: BigNumber;
- gasPrice: number;
- gasLimit: number;
- timestamp: number;
- data?: any;
- type?: number;
- tknTo?: string;
- tknValue?: BigNumber;
AionApiClient
Aion api client that implement IsingleApiFullClient
Parameters
-
config
IAionConfig
getNetwork
Get network name: mainnet, amity and mastery.
getBlockByNumber
Get block by number, block information doesn't contains transaction details
Parameters
-
blockNumber
string block number's hex string
Returns any eth_getBlockNumber response's result
getBlockNumber
Get latest block number
Returns any eth_getBlockNumber response's result
getTransactionStatus
Get transaction status.
Parameters
-
hash
string transaction hash
Returns any if eth_getTransactionReceipt is null, returns null; else return object { status: true/false, blockNumber: intger, gasUsed: integer }
getTransactionsByAddress
Get transactions by the given address
Parameters
Returns any map of object structure which contains: key is hash hash: string, with prefix 0x timestamp: milli-seconds from 1970 from: sender to: receiver value: transfer amount status: 'CONFIRMED' or 'FAILED' blockNumber: hex string fee: integer
sendTransaction
Send transaction
Parameters
-
unsignedTx
AionUnsignedTx unsigned transaction build by buildTransaction -
signer
T localSigner or hardware -
signerParams
any localSigner: {private_key} hardware:{derivationIndex}
Returns Promise<AionPendingTx>
getTokenIconUrl
throw not implementated error
Parameters
buildTransaction
TODO: not general enough. Build transaction
options parameters contains: gasLimit, gasPrice, isTokenTransfer, data(optional), contractAddr(optional), tokenDecimal(optional). if isTokenTransfer is true, transaction value is zero and transaction to is token contract creation address, to parameter is encoded in data.
Parameters
-
from
string transaction sender -
to
string amount receiver -
value
BigNumber amount value -
options
{gasLimit: number, gasPrice: number, isTokenTransfer: boolean, data: any?, contractAddr: string?, tokenDecimal: number?} extra parameters
Returns Promise<AionUnsignedTx>
AionPendingTx
Aion pending transaction
- hash: string;
- status: "PENDING";
- to: string;
- from: string;
- value: BigNumber;
- tknTo?: string;
- tknValue?: BigNumber;
- timestamp: number;
- gasPrice: number;
- gasLimit: number;