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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tron-wallet-snap

v0.3.4

Published

A Tron wallet Snap for MetaMask

Readme

Tron Wallet Snap

A MetaMask Snap for managing Tron network accounts. The snap now supports the complete account lifecycle and core keyring capabilities such as TRX transfers, transaction signing / broadcasting, and message signing.

📚 文档

Features

  • Create Tron accounts (mainnet and Shasta testnet)
  • List / get / delete Tron accounts and filter by chain
  • Discover accounts derived from a mnemonic
  • List assets and fetch account balances via MetaMask Keyring API
  • Query on-chain transaction history (via TronGrid)
  • Sign messages using the account private key
  • Build + sign + send TRX transfers via keyring_submitRequest
  • Sign raw transactions and broadcast signed payloads

RPC Methods

In addition to the Keyring API, the snap exposes convenience RPC helpers (invoked via wallet_invokeSnap):

  • tron_sendTransfer – build/sign/broadcast a TRX transfer
  • tron_signMessage – sign arbitrary strings with the selected account
  • tron_signTransaction – sign a raw transaction hex blob
  • tron_broadcastTransaction – broadcast a signed payload to TronGrid

See the /tron page in the site package for a working UI that calls these RPC methods end-to-end.

Development

# Install dependencies
yarn install

# Build the snap
yarn build

# Start development server
yarn start

# Run tests
yarn test

# Run tests in watch mode
yarn test:watch

Usage

This snap implements the Keyring API and can be used through MetaMask's keyring interface.

Quick Start

const snapId = 'npm:tron-wallet-snap';

// 1. Install the snap
await window.ethereum.request({
  method: 'wallet_requestSnaps',
  params: { [snapId]: {} },
});

// 2. Create a Tron account
const account = await window.ethereum.request({
  method: 'wallet_invokeKeyring',
  params: {
    snapId,
    request: {
      method: 'keyring_createAccount',
      params: {
        options: {
          scope: 'tron:mainnet',
          accountNameSuggestion: 'My Tron Account',
        },
      },
    },
  },
});

console.log('Account address:', account.address);

Creating an Account

To create a Tron account, use the keyring_createAccount method with the following options:

{
  scope: 'tron:mainnet', // or 'tron:shasta'
  entropySource: 'm', // optional, defaults to 'm'
  index: 0, // optional, auto-increments if not provided
  derivationPath: "m/44'/195'/0'/0/0", // optional, overrides index
  accountNameSuggestion: 'My Tron Account' // optional
}

For detailed API documentation, see API.md.

Architecture

The snap follows a clean architecture pattern:

  • Entities: Core domain models (TronAccount, etc.)
  • Infrastructure: Adapters for external services (SnapClient, Logger)
  • Store: Data persistence layer (TronAccountRepository)
  • Use Cases: Business logic (AccountUseCases)
  • Handlers: API handlers (KeyringHandler)

Manual Verification (QA Checklist)

  1. Environment

    • cd packages/tron-snap && yarn start to watch/rebuild the snap.
    • cd packages/site && yarn start to run the test dapp at http://localhost:8000/tron.
    • Install MetaMask Flask, connect to the site, and approve the snap.
  2. Account lifecycle

    • Use the /tron page to create both mainnet & Shasta accounts.
    • Run keyring_listAccounts / keyring_getAccount / keyring_deleteAccount via the UI buttons.
  3. Balance & history

    • Select an account → “List Assets” → “Get Balances” → “List Transactions”.
    • Cross-check returned balances with TronScan if needed.
  4. Submit request capabilities

    • Message signing: click “Sign Message” in the test page, confirm signature appears in console.
    • Send transfer: fill recipient address & amount, invoke “Send Transfer” (snap builds + signs + broadcasts). Verify returned txid on TronScan (testnet if using Shasta scope).
    • Sign transaction: provide transaction hex, ensure snap returns signed payload.
    • Broadcast transaction: paste signed payload, ensure txid is returned.
  5. Error scenarios

    • Try invoking submitRequest with an unknown account id to confirm snap surfaces Account not found.
    • Disconnect network or use invalid TronGrid endpoint to verify ExternalServiceError logging.

Notes

  • Tron addresses are generated using the BIP44 derivation path m/44'/195'/0'/0/index.
  • Uses Keccak-256 for address generation (standard for Tron) and Base58Check encoding.
  • The snap communicates with TronGrid for balances, transactions, and latest block metadata.

Testing

The project includes comprehensive test coverage:

  • Unit Tests: Test individual components and functions
    • KeyringHandler.test.ts - Tests for the Keyring API handler
    • AccountUseCases.test.ts - Tests for account business logic
    • TronAccountRepository.test.ts - Tests for account persistence
    • mappings.test.ts - Tests for data mapping functions

Run tests with:

yarn test

Site Integration

A test page is available at /tron in the site package to interact with the Tron snap:

  1. Start the Tron snap: cd packages/tron-snap && yarn start
  2. Start the site: cd packages/site && yarn start
  3. Navigate to http://localhost:8000/tron in your browser
  4. Connect MetaMask Flask and install the Tron snap
  5. Create and manage Tron accounts