![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
TronWeb is a JavaScript library that provides a comprehensive set of tools for interacting with the TRON blockchain. It allows developers to create, deploy, and interact with smart contracts, manage accounts, and perform transactions on the TRON network.
Account Management
This feature allows you to manage TRON accounts, including retrieving account information such as balance and transaction history. The code sample demonstrates how to initialize TronWeb and fetch account details using an address.
const TronWeb = require('tronweb');
const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
privateKey: 'your_private_key'
});
async function getAccountInfo(address) {
const accountInfo = await tronWeb.trx.getAccount(address);
console.log(accountInfo);
}
getAccountInfo('your_tron_address');
Smart Contract Interaction
TronWeb allows you to interact with smart contracts on the TRON network. This code sample shows how to call a method on a deployed smart contract by specifying the contract address, method name, and parameters.
const TronWeb = require('tronweb');
const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
privateKey: 'your_private_key'
});
async function callContractMethod(contractAddress, methodName, parameters) {
const contract = await tronWeb.contract().at(contractAddress);
const result = await contract[methodName](...parameters).call();
console.log(result);
}
callContractMethod('contract_address', 'methodName', ['param1', 'param2']);
Transaction Management
This feature enables you to manage transactions on the TRON network, including sending TRX tokens. The code sample demonstrates how to send a transaction to a specified address with a given amount.
const TronWeb = require('tronweb');
const tronWeb = new TronWeb({
fullHost: 'https://api.trongrid.io',
privateKey: 'your_private_key'
});
async function sendTransaction(to, amount) {
const transaction = await tronWeb.trx.sendTransaction(to, amount);
console.log(transaction);
}
sendTransaction('recipient_address', 1000);
Web3.js is a popular JavaScript library for interacting with the Ethereum blockchain. It provides similar functionalities to TronWeb, such as account management, smart contract interaction, and transaction handling, but is specifically designed for Ethereum. While TronWeb is tailored for the TRON network, Web3.js is the go-to library for Ethereum developers.
Ethers.js is another JavaScript library for Ethereum, offering a more lightweight and modular approach compared to Web3.js. It provides similar functionalities to TronWeb but focuses on Ethereum. Ethers.js is known for its simplicity and ease of use, making it a popular choice among Ethereum developers.
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.
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.
You can run the example with yarn example
or npm run-script example
. Don't forget to run yarn install
beforehand.
Full Node - https://api.trongrid.io:8090
Solidity Node - https://api.trongrid.io:8091
Event Server - https://api.trongrid.io
You can also set up your own private network, but you need to solve cross-domain CORS. The following nginx
configuration file will allow you to route the headers properly:
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;
}
}
You need to initiate a new TronWeb instance like below:
import TronWeb from 'TronWeb'
const HttpProvider = TronWeb.providers.HttpProvider; // This provider is optional, you can just use a url for the nodes instead
const fullNode = new HttpProvider('https://api.trongrid.io:8090'); // Full node http endpoint
const solidityNode = new HttpProvider('https://api.trongrid.io:8091'); // Solidity node http endpoint
const eventServer = 'https://api.trongrid.io/'; // Contract events http endpoint
const privateKey = 'da146374a75310b9666e834ee4ad0866d6f4035967bfc76217c5a495fff9f0d0';
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
privateKey
);
// The majority of the function calls are asynchronus,
// meaning that they cannot return the result instantly.
// These methods therefore return a promise, which you can await.
const balance = await tronWeb.getBalance(address);
console.log({ balance });
// You can also bind a `then` and `catch` method.
tronWeb.getBalance(address).then(balance => {
console.log({ balance });
}).catch(err => console.error(err));
// If you'd like to use a similar API to Web3, provide a callback function.
tronWeb.getBalance(address, (err, balance) => {
if(err)
return console.error(err);
console.log({ balance });
});
FAQs
JavaScript SDK that encapsulates the TRON HTTP API
The npm package tronweb receives a total of 18,709 weekly downloads. As such, tronweb popularity was classified as popular.
We found that tronweb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.