@makkii/app-tron
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

@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

signTransaction

Sign transaction by signer

Parameters
  • tx TronUnsignedTx
  • signer T localSigner or hardware
  • signerParam 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

Returns Promise<TronKeypair>

validatePrivateKey

Validate private key

not implemented

Parameters

validateAddress

Validate address

Parameters

Returns boolean

getAccountFromMnemonic

Get account from mnemonic

Parameters

Returns Promise<TronKeypair>

getAccountFromHardware

Get account from hardware

not implemented

Parameters
  • _address_index number
  • hardware 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 TronUnsignedTx
  • params {} {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

getNetwork

Get network

Returns any nework mainnet|shasta

updateConfiguration

Update tron api config

Parameters

getBlockByNumber

Get block by number

not implemented

Parameters

getBlockNumber

Get block height

not implemented

getTransactionStatus

Get transaction status by tx hash

Parameters

Returns Promise<TronTxStatus>

getTransactionExplorerUrl

Get an explorer url showing transaction details

Parameters

Returns string url

getBalance

Get an account's balance

Parameters

Returns Promise<BigNumber> balance

sendTransaction

Send transaction

Parameters
  • unsignedTx TronUnsignedTx unsigned transaction build by buildTransaction
  • signer T localSigner or hardware
  • signerParams 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;

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.2
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.2
    0
  • 0.1.1
    0

Package Sidebar

Install

npm i @makkii/app-tron

Weekly Downloads

0

Version

0.1.2

License

ISC

Unpacked Size

61.4 kB

Total Files

47

Last publish

Collaborators

  • makkii-dev
  • rleor