TRON blockchain api client for nodejs and browser
Tron api cli uses trxplorer.io api (https://api.trxplorer.io) to interract with TRON blockchain protocol
yarn install tron-api-cli- Query blockchain (blocks, transactions, accounts, representative etc ...)
- Create transactions for contracts (send trx, freeze/unfreeze trx, vote etc ...)
- Sign transaction
import tronapi from "tron-api-client"
# Get user transactions
tronapi.account('TXuLKjf8J8aCKgDgA5uczwn1yQNYVPLocY').getTransactions().then((transactions)=>{ console.log(transactions)})
# Send trx with account/pkey (transaction is automatically signed before broadcasting to TRON network)
tronapi.account('TXuLKjf8J8aCKgDgA5uczwn1yQNYVPLocY',pkey).sendTRX({to:'TZuLFjf8J8aCKgDgA5uczwn1yQNYVPLocY',amount:100})Kind: global class
| Param | Type |
|---|---|
| options | Options |
Get an instance of account client
Kind: instance method of Cli
| Param | Type | Description |
|---|---|---|
| address | string |
the account address to query |
| pkey | string |
the account private key (optional) |
Checks if an account with a name or an address (or both) exists
Kind: instance method of Cli
| Param | Type | Description |
|---|---|---|
| criteria | AccountExistsCriteria |
(see api.trxplorer.io for details) |
Get an instance of witness client
Kind: global class
- AccountCli
- new AccountCli(endpoint, address, privateKey)
- .getInfo() ⇒
AccountInfo - .getTransactions(criteria)
- .getAllVotes(criteria)
- .getAllFreeze(criteria)
- .getTokens(criteria)
- .sendTRX(toAddress, amount, pkey) ⇒
TransactionResult - .sendToken(toAddress, tokenName, amount, pkey) ⇒
TransactionResult - .vote()
- .freeze(amount, duration) ⇒
TransactionResult - .unfreeze() ⇒
TransactionResult - .widthdraw() ⇒
TransactionResult - .sign(transaction)
- .createWitness(url)
- .update(name)
Account client
| Param | Type | Description |
|---|---|---|
| endpoint | string |
Api endpoint |
| address | string |
Account address |
| privateKey | string |
Account private key (optional) |
accountCli.getInfo() ⇒ AccountInfo
Get basic account informations
Kind: instance method of AccountCli
Get transactions where current account is involved
Kind: instance method of AccountCli
| Param | Type |
|---|---|
| criteria | TransactionCriteria |
Get all votes associated to current account
Kind: instance method of AccountCli
| Param | Type |
|---|---|
| criteria | VoteCriteria |
Get all freeze/unfreeze history associated to current account
Kind: instance method of AccountCli
| Param | Type |
|---|---|
| criteria | VoteCriteria |
Get the token balances associated to this account
Kind: instance method of AccountCli
| Param | Type |
|---|---|
| criteria | TokenCriteria |
accountCli.sendTRX(toAddress, amount, pkey) ⇒ TransactionResult
Send an amount of TRX to an address
/!\ It is highly recommended to use this method with an offline signature strategy
Kind: instance method of AccountCli
Returns: TransactionResult - transaction result
| Param | Type |
|---|---|
| toAddress | string |
| amount | number |
| pkey | string |
accountCli.sendToken(toAddress, tokenName, amount, pkey) ⇒ TransactionResult
Send an amount of the specified token to an address
/!\ It is highly recommended to use this method with an offline signature strategy
Kind: instance method of AccountCli
Returns: TransactionResult - transaction result
| Param | Type |
|---|---|
| toAddress | string |
| tokenName | string |
| amount | number |
| pkey | string |
Vote for representatives
Kind: instance method of AccountCli
accountCli.freeze(amount, duration) ⇒ TransactionResult
Freeze an amount of TRX for a given duration (in days)
/!\ It is highly recommended to use this method with an offline signature strategy
Kind: instance method of AccountCli
Returns: TransactionResult - transaction result
| Param | Type |
|---|---|
| amount | number |
| duration | number |
accountCli.unfreeze() ⇒ TransactionResult
Unfreeze the amount of TRX that can be frozen at this time
/!\ It is highly recommended to use this method with an offline signature strategy
Kind: instance method of AccountCli
Returns: TransactionResult - transaction result
accountCli.widthdraw() ⇒ TransactionResult
Withdraw available allowance (for super representatives rewarded for producing blocks)
/!\ It is highly recommended to use this method with an offline signature strategy
Kind: instance method of AccountCli
Returns: TransactionResult - transaction result
Sign a transaction with provided private key
Kind: instance method of AccountCli
| Param | Type |
|---|---|
| transaction | Transaction |
Make current account become a witness if possible
Kind: instance method of AccountCli
| Param | Type | Description |
|---|---|---|
| url | string |
representative url |
Update account informations
Kind: instance method of AccountCli
| Param | Type | Description |
|---|---|---|
| name | string |
the name associated to current account address |
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| balance | number |
Current trx balance |
| bandwidth | number |
current accoutn bandwidth |
| frozen | number |
amount of frozen trx |
| power | number |
power associated to account |
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| txId | string |
Transaction id (if transaction succeeded) |
| success | boolean |
transaction succeeded ? |
| messageError | string |
the error message |
Kind: global class
Block client
| Param | Type | Description |
|---|---|---|
| endpoint | string |
Api endpoint |
Get the latest available block
Kind: instance method of BlockCli
Add Bock reference to a transaction
Kind: instance method of BlockCli
| Param | Type |
|---|---|
| transaction | Transaction |
Kind: global class
Witness client
| Param | Type | Description |
|---|---|---|
| endpoint | string |
Api endpoint |
Get all witnesses matching the criteria
Kind: instance method of WitnessCli
| Param | Type |
|---|---|
| criteria | WitnessCriteria |