What is Tron-Web?
TronWeb aims to deliver a unified, seamless development experience influenced by Ethereum's Web3 implementation. We have taken the core of Web3 and expanded upon it to unlock the functionality of TRON's unique feature set along with offering new tools for integrating DApps in the browser, Node.js and IoT devices.
Compatibility
- Version built for Node.js v6 and above
- Version built for browsers with more than 0.25% market share
You can access either version specifically from the dist/
folder.
TronWeb is also compatible with frontend frameworks such as Angular, React and Vue.
You can also ship TronWeb in a Chrome extension.
Installation
- npm: npm install tronweb
- bower: bower install tronweb
Example
You can run the example with yarn example
or npm run-script example
. Don't forget to run yarn install
beforehand.
Documentation (Currently for 1.0, this branch is 2.0)
TRON provides a private network to test with
upstream fullnodeapi_server {
ip_hash;
server 39.105.72.181:8090;
}
server {
listen 80;
listen [::]:80;
server_name testapi.trondapps.org;
access_log /var/log/nginx/server.access.log main;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 6;
gzip_types text/css text/javascript application/css application/javascript image/jpeg image/gif image/png;
gzip_vary on;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With,Content-Type,Accept;
add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://fullnodeapi_server;
proxy_redirect off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Creating an Instance
You need to initiate a new TronWeb instance like below:
import TronWeb from 'TronWeb'
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider('https://api.trongrid.io:8090');
const solidityNode = new HttpProvider('https://api.trongrid.io:8091');
const eventServer = 'https://api.trongrid.io/';
const privateKey = 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0';
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
);
const balance = await tronWeb.trx.getBalance(address);
console.log({ balance });
tronWeb.trx.getBalance(address).then(balance => {
console.log({ balance });
}).catch(err => console.error(err));
tronWeb.trx.getBalance(address, (err, balance) => {
if(err)
return console.error(err);
console.log({ balance });
});
GitHub
https://github.com/tronprotocol/tron-web.git