Natively Pronounced Mandarin
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

@faast/tron-payments

0.0.7 • Public • Published

tron-payments

Library to assist in payment processing on tron. It first allows for generation of address according to the BIP44 standard.

Bitcore is used for deterministic public and private keys. Please see the BIP32 standard for more information (BIP32).

Some work is inspired off of the prior work done by tron-bip44

Coming soon: tools to sign transactions passed down from the server connected to web3.

Getting Started

npm install --save tron-payments

Create a new wallet (DON'T DO THIS ON PRODUCTION):

let tronPayments = require('@faast/tron-payments')()
let keys = tronPayments.generateNewKeys()
console.log(keys.xpub)
console.log(keys.xprv)

Generate an tron deposit address from a public seed (xpub). This is useful if you are a hot wallet and don't store the private key. You will need to keep track of which path node you are on (increasing INT):

let depositAddress = tronPayments.bip44(keys.xpub, 1234) // for path m/44'/195'/0/1234
console.log(depositAddress)

Get the private key for an address on a specific path:

let privateKey = tronPayments.getPrivateKey(keys.xprv, 1234) // for path m/44'/195'/0/1234

Get the public key from a private key:

let address = tronPayments.privateToPublic(privateKey) // for path m/44'/195'/0/1234
if(address === depositAddress){
  console.log('this library works')
} else {
  console.log('better not use this library')
}

Get the derived xpub key from a hardened private key:

let xpub = tronPayments.getXpubFromXprv(xprv) // for path m/44'/195'/0'/0/1234

Get the balance of an address:

tronPayments.getBalanceFromPath(xpubOnPath, 3, function (err, balance) {
 
})

Generate a sweep transaction for a deposit address, then broadcast it:

tronPayments.getSweepTransaction(xprv, 3, to, function (err, signedtx) {
  tronPayments.broadcastTransaction(signedtx, function (err, txHash) {
 
  })
})

Generate a simple send transaction

tronPayments.getSendTransaction(privateKey, amountInSun, to, function (err, signedtx) {
  // You still need to broadcast the transaction
})

Get a transaction and check if it is confirmed based on a number of blocks:

// 2 blocks is considered confirmed
tronPayments.getTransaction(txHash, 2, function (err, tx) {
 
})

See test/test.js for more utilities

Note: It is suggested to generate your Private key offline with FAR more entropy than the default function, then use getXpubFromXprv. You have been warned!

License

MIT

install

npm i @faast/tron-payments

Downloadsweekly downloads

156

version

0.0.7

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability