npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coolwallet/trx

v1.1.9

Published

Coolwallet Tron sdk

Downloads

50

Readme

CoolWallet Tron (TRX) SDK

Typescript library with support for the integration of TRX for third party application, include the functionalities of generation of addresses, signed transactions, and staking.

Install

npm install @coolwallet/trx

Usage

import TRX from '@coolwallet/trx';
import { crypto } from '@coolwallet/core';
import { createTransport } from '@coolwallet/transport-web-ble';

const trx = new TRX();

const transport = await createTransport();

const { privateKey: appPrivateKey } = crypto.key.generateKeyPair();

const appId = 'appId that had been registered by wallet';

const address = await trx.getAddress(transport, appPrivateKey, appId, 0);

const normalTransaction = {
    refBlockBytes: "c75b",
    refBlockHash: "7cfc890c6e4d7a15",
    expiration: 1583304414000,
    timestamp: 1583268416080,
    contract: {
        ownerAddress: "41bf97a54f4b829c4e9253b26024b1829e1a3b1120",
        toAddress: "41859009fd225692b11237a6ffd8fdba2eb7140cca",
        amount: 100000000
    }
};

const signTxData = {
  transport,
  appPrivateKey,
  appId,
  addressIndex: 0,
  transaction: normalTransaction
}

const normalTx = await trx.signTransaction(signTxData);

const trc20Transaction = {
    refBlockBytes: "5a40",
    refBlockHash: "12cd29483be4900a",
    expiration: 1638339660000,
    timestamp: 1638339602030,
    contract: {
        ownerAddress: "411634b4103bd6feb3a9f9e9eb937f484c3c8b0046",
        contractAddress: "41a614f803b6fd780986a42c78ec9c7f77e6ded13c",
        receiverAddress: "4139e6a453301f6d5d228966dd8d742f1f861bd40f",
        amount: 2000000
    }
    feeLimit: 150000000,
    option: {
        symbol: "USDT",
        decimals: 6
    }
}

const trc20SignTxData = {
  transport,
  appPrivateKey,
  appId,
  addressIndex: 0,
  transaction: trc20Transaction
}

const trc20Tx = await trx.signTRC20Transfer(trc20SignTxData);

Methods

getAddress

Description

The address generated is compatible to BIP44 with account and change set to 0, which means calling getAddress with addressIndex = i will get the address of folllowing BIP44 path:

m/44'/195'/0'/0/{i}

In the design of current hardware, we only support path m/44'/195'/0'/0/{i} for speed optimization. This might change in the future and we will then open a more general interface to deal with custom path.

async getAddress(
    transport: type.Transport,
    appPrivateKey: string,
    appId: string,
    addressIndex: number
): Promise<string>

Arguments

| Arg | Description | Type | Required | |:-------------:|:--------------------------------------------:|:---------:|:---------:| | transport | Object to communicate with CoolWallet device | Transport | True | | appPrivateKey | Private key for the connected application | string | True | | appId | ID for the connected application | string | True | | addressIndex | The from address index in BIP44 derivation | number | True |

Sign Transaction

Description

CoolWallet currently support various signing methods and contracts based on the type of the transaction. The SignTxData and Transaction arguments are the essentail data fields for TRX transactions. Depends on the type of transaction, the extended arguments may vary.

SignTxData Arguments

| Arg | Description | Type | Required | |:-------------:|:--------------------------------------------------------------------:|:---------:|:---------:| | transport | Object to communicate with CoolWallet device | Transport | True | | appPrivateKey | Private key for the connected application | string | True | | appId | ID for the connected application | string | True | | addressIndex | The from address index in BIP44 derivation | number | True | | confirmCB | Callback of confirmation data to the connected application | Function | False | | authorizedCB | Callback of authorized transaction data to the connected application | Function | False |

Transaction Arguments

| Arg | Description | Type | Required | |:-------------:|:----------------------------------------------------------:|:------:|:--------:| | refBlockBytes | Reference to the bytes of the hash of the latest block | string | True | | refBlockHash | Reference to the bytes of the height of the latest block | string | True | | expiration | The time period between transaction creation and broadcast | number | True | | timestamp | Timestamps for the transaction | number | True |

The extended arguments may vary depend on the type of the transaction. The transaction can be for transfering (signTransaction, signTRC20Transfer) or staking (signFreeze, signUnfreeze, signVoteWitness, signWithdrawBalance) purposes.

signTransaction

Description

Sign TRX Transaction.

async signTransaction(signTxData: type.NormalTradeData): Promise<string> 

NormalContract Arguments

| Arg | Description | Type | Required | |:------------:|:----------------------:|:----------------:|:--------:| | ownerAddress | The from address | string | True | | toAddress | The to address | string | True | | amount | The amount to transfer | number | string | True |

signTRC20Transfer

Description

Sign TRC20 Transfering Transaction

async signTRC20Transfer(signTxData: type.TRC20TransferData): Promise<string>

TRC20TransferContract Arguments

| Arg | Description | Type | Required | |:---------------:|:------------------------------:|:----------------:|:--------:| | ownerAddress | The from address | string | True | | contractAddress | Address of the TRC-20 contract | string | True | | receiverAddress | The to address | string | True | | amount | The amount to transfer | number | string | True |