@opentron/java-tron-provider

Web3 provider that uses the `java-tron` HTTP API.

Usage no npm install needed!

<script type="module">
  import opentronJavaTronProvider from 'https://cdn.skypack.dev/@opentron/java-tron-provider';
</script>

README

@opentron/java-tron-provider

Web3.js compatible provider that uses the java-tron HTTP API.

Install

Library:

npm install @opentron/java-tron-provider

Proxy server:

npm install -g @opentron/java-tron-provider
TRON_NETWORK=nile java-tron-web3-proxy

Usage

import Web3 from "web3";
import createJavaTronProvider from "@opentron/java-tron-provider";

const provider = createJavaTronProvider({
  network: "nile", // defaults to mainnet
  privateKey: "priv key...", // only required if sending transactions
  // (optional) function that maps bytecode to { name, abi } object.
  mapBytecode: (bytecode) => {
    // e.g.:
    if (bytecode === "0xdeadbeef") {
      return {
        name: "MappedName",
        abi: [
          /* some abi */
        ],
      };
    }
  },
});

const web3 = new Web3(provider);

// ... etc.

mapBytecode(optional): Tron supports publishing an ABI and contract name when deploying a contract but web3 only passes the bytecode to the provider. This function helps the provider map the bytecode to a { name, abi } object.

See ./test/web3.js for more usage examples.

See ../truffle-tron-demo for usage example with Truffle.

Proxy Server

Runs the java-tron provider as a JSON-RPC HTTP server.

Example usage:

# start server
node bin/proxy-server.js
# start server for nile
TRON_NETWORK=nile node bin/proxy-server.js

Use server as regular Ethereum JSON-RPC API server:

curl \
  --data '{"method":"eth_getBlockByNumber","params":["latest", true],"id":1,"jsonrpc":"2.0"}' \
  -H "Content-Type: application/json" \
  -X POST localhost:8333 \
  | jq

Optional Configuration:

See config object at top of ./bin/proxy-server.js for latest documentation.

IP_ADDRESS=<ip address to bind to>
PORT=<port to bind>
TRON_NETWORK=<tron network>
# defaults to selecting node based on TRON_NETWORK
TRON_NODE=<tron node>
# enable verbose output (logs JSON-RPC requests)
# can also be used as CLI flag --verbose
# defaults to false
VERBOSE=1
# debug logs:
DEBUG=java-tron-provider

TODO

  • use gasLimit as feeLimit...
  • transaction.input (.data sent with original transaction)
  • eth_chainId
  • Test contract deployment
  • Pass an array of contract JSON info to java-tron-provider constructor so it can set the on chain Tron ABI and contract name when creating a contract?
  • Implement signing transactions using a private key string
  • Webpack build for browsers
  • Reduce dependencies / package size (e.g. dependency on web3)
  • tronlink-provider that extends this provider but uses TronLink for signing transactions.