# Introduction
TronGridJS is a Javascript library for utilizing TronGrid APIs to retrieve blockchain data from the TRON network.
# Compatibility
Version built for Node.js v6 and above.
Version built for browsers with more than 0.25% market share.
TronGridJS is also compatible with front-end frameworks like:
Angular
React
Vue
TronGridJS can also be shipped in a Chrome extension.
# Installation
<a href="https://www.npmjs.com/package/trongrid" target="_blank">**TronGridJS - NPM Package**</a>
**NPM**
**Yarn**
# Build Steps
If you would like to download and build locally, please follow the below steps:
# Supported APIs
TronGridJS allows for easy access to the new v1 APIs provided by TronGrid. Since TronGridJS uses TronWeb as a dependency, you need to initialize TronGridJS with TronWeb as a constructor parameter:
Description | Substitutes |
Returns information about the account at `accountAddress ` | /wallet/getaccount |
Parameter | Description | Values |
onlyConfirmed | Shows only the situation at latest confirmed block. | True | False (Default False) |
Description | Substitutes |
Returns all the transactions related to the account at `accountAddress ` | /walletextension/gettransactionfromthis /walletextension/gettransactiontothis |
Parameter | Description | Values |
only_confirmed | Shows only confirmed. | true | false (default false) |
only_unconfirmed | Shows only unconfirmed. | true | false (default false) |
only_to | Only transaction to address. | true | false (default false) |
only_from | Only transaction from address. | true | false (default false) |
limit | The requested number of transaction per page. | Default 20. Max 200. |
fingerprint | The fingerprint of the last transaction returned by the previous page. | |
order_by | Sorts the results of the query. Example: order_by=timestamp, desc | |
min_timestamp | The minimum transaction timestamp. | default 0 |
max_timestamp | The maximum transaction timestamp. | default now |
Description | Substitutes |
Returns all the assets on the TRON platform. | N/A |
Parameter | Description | Value |
order_by | Sorts the results. | Accepted fields: id name total_supply start_time end_time |
Description | Substitutes |
Returns an asset identified by either the owner address or its own ID. | /wallet/getassetissuebyaccount /wallet/getassetissuebyid |
Description | Substitutes |
Returns all the assets with name `assetName ` | /wallet/getassetissuelistbyname /wallet/getassetissuelist |
Parameter | Description | Value |
limit | The requested number of assets per page. | Default 20. Max 200. |
fingerprint | The fingerprint of the last asset returned by the previous page. When there is a pagination, the minimum limit is set to 20. | |
order_by | Sorts the results of the query. | Accepted fields: id name total_supply start_time end_time Example: order_by=start_time,desc (starts from the most recent ICO) order_by=id,asc (starts from the oldest) |
only_confirmed | Shows only the situation at latest confirmed block. | true | false (default: false) |
Description | Substitutes |
Returns all the events of a specific block. The identifier can be either `latest ` or a block number. | N/A |
Description | Substitutes |
Returns all the events emitted by a smart contract. | N/A |
Parameter | Description | Value |
only_confirmed | Shows only confirmed. | |
only_unconfirmed | Shows only unconfirmed. | |
event_name | The name of the event. | |
block_number | The block number for which the events are required. | |
min_timestamp | The minimum block timestamp. | |
max_timestamp | The maximum block timestamp. | |
order_by | Sorts the events. | Accepted values: timestamp, asc timestamp, desc (Default) |
limit | For pagination. | Default 20 Max 200 |
fingerprint | The fingerprint of the last event retrieved in the page. | |
Description | Substitutes |
Returns all the events emitted in the transaction specified by `id ` | N/A |
# Responses & Pagination
Any API will return a response with a success property, a data array, and a meta object. For example, `await tronGrid.asset.getAll()
` will return something like:
As you can see, in the meta fields, there is the fingerprint you must pass to next request as an option in order to get next page.
# Usage
## Regular Use
Install TronWeb
Initialize TronWeb and create a TronGridJS instance
**Example**
## Plugin
You can plug TronGrid in TronWeb to substitute the standard method `tronWeb.trx.getTransactionRelated(...)
` with a method that calls internally `tronGrid.account.getTransactions(...)
`.
To use it, the user must register TronGrid as a plugin:
It may sometimes be necessary to pass some options to the plugin interface. Looking at the test in `test/unit/plugin.test.js
`, you can register the plugin as:
For the MVP, the experimental access code can be passed as an option to the plugin:
After registering the plugin, call:
and
will return results from TronGrid under the hood.