1.1.2 • Published 3 years ago

@brickglobal/coin_tron v1.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Tron Lib

npm version npm downloads

Installation

Node.js:

// npm
$ npm install @brickglobal/coin_tron
// yarn
$ yarn add @brickglobal/coin_tron

Creating an Instance

First off, in your javascript file, define TronLib:

const { TronLib } = require('@brickglobal/coin_tron');

ES module

import { TronLib } from "@brickglobal/coin_tron";

When you instantiate TronLib you must provide

  • fullNodeUri
  • privateKey: optional
const tronLib = new TronLib("https://api.nileex.io/")
// or
const tronLib = new TronLib("https://api.nileex.io/", "your private key")

Methods

There are total 4 methods:

1. createAccount

Using to create account

Usage

tronLib.createAccount();

Params

Null

Return

Promise { <pending> }
> {
    privateKey: string,
    publicKey: string,
    address {
      base58: string,
      hex: string,
    }
  }

Example

tronLib.createAccount();

// return
Promise { <pending> }
> {
    address: {
      base58: "TPbBpRXnt6ztse8XkCL******", 
      hex: "4195679F3AAF5211991781D4****",
    }
    privateKey: "08089C24EC3BAEB34254DDF5297CF8F******"
    publicKey:  "04EE63599802B5D31A29C95CC7DF04F427E8F0A124BED9333F3A80404ACFC31276594962656EF******"
  }

2. sendTrx

Sends TRX from one address to another.

WARNING: Do not use this in any web / user-facing applications. This will expose the private key.

Usage

tronLib.sendTrx();

Params

ParameterDescriptionData Type
receiverAddressAddress to send TRX to, converted to a hex string.Hex String
amountAmount of TRX to send (units in SUN)Integer (units in SUN)
privateKeyOptionally provide a private key to sign the transaction. If left blank, will use the address associated with the private key.Hex string

Return

Promise { <pending> }
> txid: string

Example

const sendtrx = await tronLib.sendTrx("TPbBpRXnt6ztse8XkCL******",1000000)
// or
const sendtrx = await tronLib.sendTrx("TPbBpRXnt6ztse8XkCL******",1000000, 'your private key')

// return
Promise { <pending> }
> 456f9e1090dc8ad6baf9237db99334d66e7d640b5********

3. sendToken10

Sends TRC10 token from one address to another.

WARNING: Do not use this in any web / user-facing applications. This will expose the private key.

Usage

tronLib.sendToken10();

Params

ParameterDescriptionData Type
receiverAddressAddress to send TRC10 to.Hex string
amountAmount of TRC10 to send.positive integers
tokenIdName of the token, matching the exact capitalization.string
privateKeyOptionally provide a private key to sign the transaction. If left blank, will use the address associated with the private key.Hex string

Return

Promise { <pending> }
> txid: string

Example

const send_token_10 = await tronLib.sendTrc10("TPbBpRXnt6ztse8XkCL******",1000000, '100010')
// or
const send_token_10 = await tronLib.sendTrc10("TPbBpRXnt6ztse8XkCL******",1000000, '100010', 'your private key')

// return
Promise { <pending> }
> 456f9e1090dc8ad6baf9237db99334d66e7d640b5********

4. sendToken20

Sends TRC20 token from one address to another.

WARNING: Do not use this in any web / user-facing applications. This will expose the private key.

Usage

tronLib.sendToken20();

Params

ParameterDescriptionData Type
receiverAddressAddress to send TRC20 to.
amountAmount of TRC20 to send.positive integers
tokenAddressContract address.Hex string
privateKeyOptionally provide a private key to sign the transaction. If left blank, will use the address associated with the private key.Hex string

Return

Promise { <pending> }
> txid: string

Example

const send_token_20 = await tronLib.sendTrc20("TPbBpRXnt6ztse8XkCL******",1000000, 'TUa1qN4ahSW7xzi5MRgA1YT******')
// or
const send_token_20 = await tronLib.sendTrc20("TPbBpRXnt6ztse8XkCL******",1000000, 'TUa1qN4ahSW7xzi5MRgA1YT******', 'your private key')

// return
Promise { <pending> }
> 456f9e1090dc8ad6baf9237db99334d66e7d640b5********
1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago