0.0.1 • Published 6 years ago

tron-api-cli v0.0.1

Weekly downloads
16
License
-
Repository
-
Last release
6 years ago

tron-api-cli

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

Install

yarn install tron-api-cli

Features

  • Query blockchain (blocks, transactions, accounts, representative etc ...)
  • Create transactions for contracts (send trx, freeze/unfreeze trx, vote etc ...)
  • Sign transaction

## Usage example

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})

Cli

Kind: global class

new Cli(options)

ParamType
optionsOptions

cli.account(address, pkey) ⇒ AccountCli

Get an instance of account client

Kind: instance method of Cli

ParamTypeDescription
addressstringthe account address to query
pkeystringthe account private key (optional)

cli.accountExists(criteria)

Checks if an account with a name or an address (or both) exists

Kind: instance method of Cli

ParamTypeDescription
criteriaAccountExistsCriteria(see api.trxplorer.io for details)

cli.witness()

Get an instance of witness client

AccountCli

Kind: global class

new AccountCli(endpoint, address, privateKey)

Account client

ParamTypeDescription
endpointstringApi endpoint
addressstringAccount address
privateKeystringAccount private key (optional)

accountCli.getInfo() ⇒ AccountInfo

Get basic account informations

Kind: instance method of AccountCli

accountCli.getTransactions(criteria)

Get transactions where current account is involved

Kind: instance method of AccountCli

ParamType
criteriaTransactionCriteria

accountCli.getAllVotes(criteria)

Get all votes associated to current account

Kind: instance method of AccountCli

ParamType
criteriaVoteCriteria

accountCli.getAllFreeze(criteria)

Get all freeze/unfreeze history associated to current account

Kind: instance method of AccountCli

ParamType
criteriaVoteCriteria

accountCli.getTokens(criteria)

Get the token balances associated to this account

Kind: instance method of AccountCli

ParamType
criteriaTokenCriteria

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

ParamType
toAddressstring
amountnumber
pkeystring

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

ParamType
toAddressstring
tokenNamestring
amountnumber
pkeystring

accountCli.vote()

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

ParamType
amountnumber
durationnumber

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

accountCli.sign(transaction)

Sign a transaction with provided private key

Kind: instance method of AccountCli

ParamType
transactionTransaction

accountCli.createWitness(url)

Make current account become a witness if possible

Kind: instance method of AccountCli

ParamTypeDescription
urlstringrepresentative url

accountCli.update(name)

Update account informations

Kind: instance method of AccountCli

ParamTypeDescription
namestringthe name associated to current account address

AccountInfo : Object

Kind: global typedef
Properties

NameTypeDescription
balancenumberCurrent trx balance
bandwidthnumbercurrent accoutn bandwidth
frozennumberamount of frozen trx
powernumberpower associated to account

TransactionResult : Object

Kind: global typedef
Properties

NameTypeDescription
txIdstringTransaction id (if transaction succeeded)
successbooleantransaction succeeded ?
messageErrorstringthe error message

BlockCli

Kind: global class

new BlockCli(endpoint)

Block client

ParamTypeDescription
endpointstringApi endpoint

blockCli.getLatest()

Get the latest available block

Kind: instance method of BlockCli

blockCli.addRef(transaction)

Add Bock reference to a transaction

Kind: instance method of BlockCli

ParamType
transactionTransaction

WitnessCli

Kind: global class

new WitnessCli(endpoint)

Witness client

ParamTypeDescription
endpointstringApi endpoint

witnessCli.getAll(criteria)

Get all witnesses matching the criteria

Kind: instance method of WitnessCli

ParamType
criteriaWitnessCriteria