Skip to content

trxplorer/tron-api-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

Param Type
options Options

cli.account(address, pkey) ⇒ AccountCli

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)

cli.accountExists(criteria)

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)

cli.witness()

Get an instance of witness client

AccountCli

Kind: global class

new AccountCli(endpoint, address, privateKey)

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

accountCli.getTransactions(criteria)

Get transactions where current account is involved

Kind: instance method of AccountCli

Param Type
criteria TransactionCriteria

accountCli.getAllVotes(criteria)

Get all votes associated to current account

Kind: instance method of AccountCli

Param Type
criteria VoteCriteria

accountCli.getAllFreeze(criteria)

Get all freeze/unfreeze history associated to current account

Kind: instance method of AccountCli

Param Type
criteria VoteCriteria

accountCli.getTokens(criteria)

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

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

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

accountCli.sign(transaction)

Sign a transaction with provided private key

Kind: instance method of AccountCli

Param Type
transaction Transaction

accountCli.createWitness(url)

Make current account become a witness if possible

Kind: instance method of AccountCli

Param Type Description
url string representative url

accountCli.update(name)

Update account informations

Kind: instance method of AccountCli

Param Type Description
name string the name associated to current account address

AccountInfo : Object

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

TransactionResult : Object

Kind: global typedef
Properties

Name Type Description
txId string Transaction id (if transaction succeeded)
success boolean transaction succeeded ?
messageError string the error message

BlockCli

Kind: global class

new BlockCli(endpoint)

Block client

Param Type Description
endpoint string Api 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

Param Type
transaction Transaction

WitnessCli

Kind: global class

new WitnessCli(endpoint)

Witness client

Param Type Description
endpoint string Api endpoint

witnessCli.getAll(criteria)

Get all witnesses matching the criteria

Kind: instance method of WitnessCli

Param Type
criteria WitnessCriteria

About

Client for Tron api via trxplorer.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published