@faast/tron-payments0.7.1 • Public • Published
Library to assist in payment processing on tron. It first allows for generation of address according to the BIP44 standard.
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.
npm install --save go-faast/tron-payments
Create a new wallet (DON'T DO THIS ON PRODUCTION):
let HdTronPayments =let keys = HdTronPaymentsconsoleconsole
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 tronPayments = hdKey: keysxprv // xpub or xprv can be used// for path m/44'/195'/0'/0/1234let depositAddress = tronPaymentslet privateKey = tronPayments // will throw Error if xpub was provided as hdKey
or, if you'd rather not us bip44 and have existing private keys or addresses:
let KeyPairTronPayments =let tronPayments = keyPairs: privateKey0 address1 privateKey2let depositAddress = await tronPayments // address for privateKey2await tronpayments // will throw error because keyPair is not a private key
Validate an address:
if tronPayments// do something
Get the public key from a private key:
let address = tronPayments // for path m/44'/195'/0/1234ifaddress === depositAddressconsoleelseconsole
Get the derived xpub key from a root xprv:
let xprvToXpub =let xpub = // derives path m/44'/195'/0'
Get the balance of an address:
let confirmedBalance unconfirmedBalance = await tronPayments
Generate a sweep transaction for an address, then broadcast it:
let unsignedTx = await tronPaymentslet signedTx = await tronPaymentslet id: txHash = await tronPayments
Generate a simple send transaction
let unsignedTx = await tronPayments// You still need to sign and broadcast the transaction
Get a transaction and check if it is confirmed:
let txInfo = await tronPaymentsif txInfoisConfirmed// txInfo.confirmations > 0
See tests for more utilities
Note: It is suggested to generate your Private key offline with FAR more entropy than the default function, then use xprvToXpub. You have been warned!