@makkii/app-tron
v0.1.2
Published
Tron application client implemented makkii-core.
Downloads
9
Readme
@makkii/app-tron
Tron application client.
This library uses some third-party service:
- Tron Grid API - you can pass in api endpoint in TronApiClient Constructor
- Explorer Api - To get transaction history, token history, we use
https://apilist.tronscan.org/api
- Transaction Explorer - To show transaction detail page, we use
https://tronscan.org/#/transaction
Installation
$ npm install @makkii/app-tron
Usage
import { TronApiClient, TronKeystoreClient, TronLocalSigner } from '@makkii/app-eth';
const api_client = new TronApiClient({
network: 'mainnet',
trongrid_api: 'https://api.trongrid.io'
});
api_client.getBalance('TCwypatGAoUhhQCnhuk3hEx8XPJYZ8Wfup')
.then(console.log)
.catch(error=>console.log(error));
const keystore_client = new TronKeystoreClient();
api_client.buildTransaction(
'TCwypatGAoUhhQCnhuk3hEx8XPJYZ8Wfup', // from address
'TJuJxDPeqbGT8epGAUcZSuMSxy5SC7aYfT', // to address
0, // amount
).then(function(unsignedTx) {
keystore_client.signTransaction(unsignedTx, new TronLocalSigner(), {
private_key: '***'
}).then(function(signedTx) {
console.log(signedTx);
});
});
API
Table of Contents
- TronKeystoreClient
- TronUnsignedTx
- TronLocalSigner
- ITronConfig
- TronPendingTx
- TronApiClient
- TronTxStatus
- TronTransaction
- TronKeypair
TronKeystoreClient
signTransaction
Sign transaction by signer
Parameters
tx
TronUnsignedTxsigner
T localSigner or hardwaresignerParam
any localSigner: {private_key} hardware:{derivationIndex}unsignedTx
unsigned transaction build by buildTransaction
Returns Promise<any> encoded transaction
generateMnemonic
Generate mnemonic by bip39
Returns string 12 length of mnemonic
recoverKeyPairByPrivateKey
Recover key pair by private key
Parameters
priKey
string
Returns Promise<TronKeypair>
validatePrivateKey
Validate private key
not implemented
Parameters
validateAddress
Validate address
Parameters
address
string
Returns boolean
getAccountFromMnemonic
Get account from mnemonic
Parameters
Returns Promise<TronKeypair>
getAccountFromHardware
Get account from hardware
not implemented
Parameters
_address_index
numberhardware
IHardware
TronUnsignedTx
Tron unsigned transaction
- to: string;
- owner: string;
- amount: number;
- timestamp: number;
- expiration: number;
- latest_block: { hash: string; number: string; };
TronLocalSigner
signTransaction
Sign transaction of tron local signer
Parameters
unsignedTx
TronUnsignedTxparams
{} {private_key: string}TronUnsignedTx
Returns any signed tron tx
ITronConfig
network
Network name.
Type: ("mainnet"
| "shasta"
)
trongrid_api
trongrid api
Type: string
explorer_api
explorer_api use to get transactions by address
Type: string
explorer
explorer url that show transaction detail
Type: string
TronPendingTx
Tron pending transaction
- to: string;
- from: string;
- value: BigNumber;
- timestamp: number;
- hash: string;
- status: "PENDING";
TronApiClient
Tron api client that implement IsingleApiClient
Parameters
config
ITronConfig
getNetwork
Get network
Returns any nework mainnet|shasta
updateConfiguration
Update tron api config
Parameters
config
ITronConfig
getBlockByNumber
Get block by number
not implemented
Parameters
blockNumber
string
getBlockNumber
Get block height
not implemented
getTransactionStatus
Get transaction status by tx hash
Parameters
hash
string tx hash
Returns Promise<TronTxStatus>
getTransactionExplorerUrl
Get an explorer url showing transaction details
Parameters
hash
string
Returns string url
getBalance
Get an account's balance
Parameters
address
string
Returns Promise<BigNumber> balance
sendTransaction
Send transaction
Parameters
unsignedTx
TronUnsignedTx unsigned transaction build by buildTransactionsigner
T localSigner or hardwaresignerParams
any localSigner: {private_key} hardware:{derivationIndex}
Returns Promise<TronPendingTx>
sameAddress
check if two address is same
Parameters
Returns boolean
buildTransaction
Build transaction
Parameters
Returns Promise<TronUnsignedTx>
TronTxStatus
Tron transaction status
- blockNumber: number;
- status: boolean;
TronTransaction
Tron transaction
- hash: string;
- timestamp: number;
- from: string;
- to: string;
- value: BigNumber;
- blockNumber: number;
- status: "CONFIRMED" | "FAILED";
TronKeypair
Tron key pair
- private_key: string;
- public_key: string;
- address: string;
- index?: number;
- sign?: (hash: any) => Buffer;