GithubHelp home page GithubHelp logo

jackliaoall / tron-web Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lizhengwei1989/tron-web

0.0 2.0 0.0 22.51 MB

Javascript API Library for interacting with the TRON Network. Similar to web3.js

License: MIT License

JavaScript 100.00%

tron-web's Introduction

What is TronWeb?

Tron Web - Developer Document

TronWeb aims to deliver a unified, seamless development experience influenced by Ethereum's Web3 implementation. We have taken the core ideas 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
  • Vue.

You can also ship TronWeb in a Chrome extension.

Installation

Node.js

npm install tronweb

or

yarn add tronweb

Browser

First, don't use the release section of this repo, it has not updated in a long time.

Then easiest way to use TronWeb in a browser is to install it as above and copy the dist file to your working folder. For example:

cp node_modules/tronweb/dist/TronWeb.js ./js/tronweb.js

so that you can call it in your HTML page as

<script src="./js/tronweb.js"><script>

Testnet

Shasta is the official Tron testnet. To use it use the following endpoint:

https://api.shasta.trongrid.io

Get some Shasta TRX at https://www.trongrid.io/shasta and play with it. Anything you do should be explorable on https://shasta.tronscan.org

Your local private network for heavy testing

You can set up your own private network, running Tron Quickstart. To do it you must install Docker and, when ready, run a command like

docker run -it --rm \
  -p 9090:9090 \
  -e "defaultBalance=100000" \
  -e "showQueryString=true" \
  -e "showBody=true" \
  -e "formatJson=true" \
  --name tron \
  trontools/quickstart

More details about Tron Quickstart on GitHub

Creating an Instance

First off, in your javascript file, define TronWeb:

const TronWeb = require('tronweb')

When you instantiate TronWeb you can define

  • fullNode
  • solidityNode
  • eventServer
  • privateKey

you can also set a

  • fullHost

which works as a jolly. If you do so, though, the more precise specification has priority. Supposing you are using a server which provides everything, like TronGrid, you can instantiate TronWeb as:

const tronWeb = new TronWeb({
    fullHost: 'https://api.trongrid.io',
    privateKey: 'your private key'
})

For retro-compatibility, though, you can continue to use the old approach, where any parameter is passed separately:

const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey)

If you are, for example, using a server as full and solidity node, and another server for the events, you can set it as:

const tronWeb = new TronWeb({
    fullHost: 'https://api.trongrid.io',
    eventServer: 'https://api.someotherevent.io',
    privateKey: 'your private key'
  }
)

If you are using different servers for anything, you can do

const tronWeb = new TronWeb({
    fullNode: 'https://some-node.tld',
    solidityNode: 'https://some-other-node.tld'
    eventServer: 'https://some-event-server.tld',
    privateKey: 'your private key'
  }
)

A full example

The better way to understand how to work with Tron is to clone the MetaCoin example and follow the instructions at https://github.com/Tronbox-boxes/metacoin-box

Contributions

In order to contribute you can

  • fork this repo and clone it locally
  • install the dependencies — npm i
  • do your changes to the code
  • build the TronWeb dist files — npm run build
  • run a local private network using Tron Quickstart
  • run the tests — npm test:node
  • push your changes and open a pull request

Recent History

2.3.2

  • Remove mixed approach instantiating tronWeb. Before you could pass the servers as an object, and the privateKey as a separate parameter. Now, you pass them either in the options object or in the params.

2.3.1

  • Adds support for not-tld domain, like http://localhost
  • Improve the new format, allow passing the privateKey as a property in the option object

2.3.0

  • Introduces new format to instantiate tronWeb, passing an options object instead that fullNode, solidityNode and eventServer as separate params
  • Fixes bug in _watch which causes a continuous update of the since parameter

Licence

TronWeb is distributed under a MIT licence.

tron-web's People

Contributors

sullof avatar kookiekrak avatar unforgivenzzz avatar serderovsh avatar kondax avatar 1119756420 avatar ujwalbattar avatar tycm4109 avatar balckdog avatar rovak avatar kolya182 avatar wevans-tron avatar devobs1 avatar fbsobreira avatar zhaohong avatar mcortesi avatar marlonbrgomes avatar nsjames avatar olegabr avatar rlaace423 avatar wxue avatar metjm avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.