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

tronhat

v1.1.5

Published

A modern development framework for Tron blockchain smart contracts

Downloads

55

Readme

TronHat 🎩

A modern, professional development framework for Tron blockchain smart contract development. TronHat provides a complete toolkit for compiling, deploying, testing, and debugging Tron smart contracts with an intuitive, developer-friendly experience.

Features

  • 🚀 CLI-based toolkit - Complete command-line interface for all development tasks
  • 🔧 Solidity compilation - Integrated Solidity compiler with version management
  • 🌐 Network management - Support for mainnet, Nile testnet, and custom networks
  • 🧪 Testing framework - Built-in Mocha/Chai testing with TronWeb integration
  • 📦 Project scaffolding - Quick project initialization with best practices
  • 🔌 Plugin system - Extensible architecture with plugin support
  • 💻 Interactive console - REPL environment with preloaded TronWeb instance
  • 📊 Deployment tracking - Automatic deployment logging and verification

Installation

Using NPX (Recommended)

npx tronhat init my-project

Global Installation

npm install -g tronhat

Local Installation

npm install --save-dev tronhat

Or use with npx:

npx tronhat --version

Quick Start

1. Initialize a new project

mkdir my-tron-project
cd my-tron-project
npx tronhat init

This creates:

my-tron-project/
├── contracts/          # Solidity contracts
├── scripts/            # Deployment scripts
├── test/              # Test files
├── tronhat.config.js  # Configuration file
└── package.json

2. Install dependencies

npm install

3. Compile contracts

npx tronhat compile

4. Run tests

npx tronhat test

5. Deploy to testnet

# Set your private key in .env file
echo "PRIVATE_KEY=your_private_key_here" > .env

# Deploy to Nile testnet
npx tronhat deploy --network nile

Configuration

TronHat uses a tronhat.config.js file for configuration:

module.exports = {
  networks: {
    development: {
      fullHost: 'http://127.0.0.1:9090',
      privateKey: 'your_development_private_key'
    },
    nile: {
      fullHost: 'https://nile.trongrid.io',
      privateKey: process.env.PRIVATE_KEY
    },
    mainnet: {
      fullHost: 'https://api.trongrid.io',
      privateKey: process.env.PRIVATE_KEY
    }
  },
  solidity: {
    version: '0.8.20',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  paths: {
    sources: './contracts',
    artifacts: './artifacts',
    cache: './cache',
    tests: './test'
  }
};

Commands

tronhat init [path]

Initialize a new TronHat project with sample contracts and configuration.

tronhat init my-project

tronhat compile

Compile all Solidity contracts in the contracts directory.

tronhat compile
tronhat compile --force  # Force recompilation

tronhat deploy

Deploy contracts using deployment scripts.

tronhat deploy                    # Deploy to development network
tronhat deploy --network nile     # Deploy to Nile testnet
tronhat deploy --network mainnet  # Deploy to mainnet
tronhat deploy --script custom-deploy.js  # Use custom script

tronhat test

Run the test suite with Mocha and Chai.

tronhat test                      # Run all tests
tronhat test --grep "MyToken"     # Run specific tests
tronhat test --network nile       # Run tests on specific network
tronhat test --bail               # Stop on first failure

tronhat console

Open an interactive console with TronWeb preloaded.

tronhat console                   # Connect to development network
tronhat console --network nile    # Connect to Nile testnet

In the console:

// TronWeb instance is available
await tronWeb.trx.getBalance('TRX_ADDRESS')

// Deploy contracts interactively
const contract = await deployContract('MyToken')

// Access artifacts
const artifact = await artifacts.readArtifact('MyToken')

Writing Contracts

Place your Solidity contracts in the contracts/ directory:

// contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyToken {
    string public name = "MyToken";
    string public symbol = "MTK";
    uint8 public decimals = 6;
    uint256 public totalSupply = 1000000 * 10**decimals;
    
    mapping(address => uint256) public balanceOf;
    
    constructor() {
        balanceOf[msg.sender] = totalSupply;
    }
    
    function transfer(address to, uint256 value) public returns (bool) {
        require(balanceOf[msg.sender] >= value, "Insufficient balance");
        balanceOf[msg.sender] -= value;
        balanceOf[to] += value;
        return true;
    }
}

Writing Tests

Create test files in the test/ directory:

// test/MyToken.test.js
const { expect } = require('chai');

describe('MyToken', function() {
  let myToken;
  let accounts;

  before(async function() {
    accounts = global.accounts;
  });

  beforeEach(async function() {
    const MyToken = await tronhat.artifacts.readArtifact('MyToken');
    const contract = await tronWeb.contract().new({
      abi: MyToken.abi,
      bytecode: MyToken.bytecode
    });
    
    myToken = await tronWeb.contract(MyToken.abi, contract.address);
  });

  it('Should have correct initial supply', async function() {
    const totalSupply = await myToken.totalSupply().call();
    expect(totalSupply.toString()).to.equal('1000000000000');
  });

  it('Should transfer tokens', async function() {
    await myToken.transfer(accounts[1], 1000).send();
    const balance = await myToken.balanceOf(accounts[1]).call();
    expect(balance.toString()).to.equal('1000');
  });
});

Deployment Scripts

Create deployment scripts in the scripts/ directory:

// scripts/deploy.js
async function main() {
  console.log('Deploying MyToken...');
  
  const MyToken = await tronhat.artifacts.readArtifact('MyToken');
  
  const myToken = await tronhat.tronWeb.contract().new({
    abi: MyToken.abi,
    bytecode: MyToken.bytecode
  });

  console.log('MyToken deployed to:', myToken.address);
  
  // Verify deployment
  const contract = await tronhat.tronWeb.contract(MyToken.abi, myToken.address);
  const name = await contract.name().call();
  console.log('Token name:', name);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

Plugin System

TronHat supports plugins for extending functionality:

// tronhat.config.js
module.exports = {
  // ... other config
  plugins: [
    'tronhat-trc20',
    'tronhat-verify'
  ]
};

Built-in Plugins

  • tronhat-trc20 - Quick TRC20 token deployment
  • tronhat-verify - Contract verification on TronScan

Environment Variables

Create a .env file for sensitive configuration:

# .env
PRIVATE_KEY=your_private_key_without_0x_prefix
NILE_URL=https://nile.trongrid.io
MAINNET_URL=https://api.trongrid.io

Network Configuration

Development Network

For local development, you can use TronBox's development network or docker containers.

Nile Testnet

Free testnet for development and testing. Get test TRX from the faucet.

Mainnet

Production Tron network. Use with caution and proper security measures.

Best Practices

  1. Security

    • Never commit private keys to version control
    • Use environment variables for sensitive data
    • Test thoroughly on testnet before mainnet deployment
  2. Testing

    • Write comprehensive tests for all contract functions
    • Test edge cases and error conditions
    • Use meaningful test descriptions
  3. Deployment

    • Use deployment scripts for reproducible deployments
    • Verify contracts after deployment
    • Keep track of deployed contract addresses

Troubleshooting

Common Issues

  1. Compilation Errors

    # Check Solidity version compatibility
    tronhat compile --force
  2. Network Connection Issues

    # Test network connectivity
    tronhat console --network nile
    > await tronWeb.trx.getCurrentBlock()
  3. Private Key Issues

    # Verify private key format (no 0x prefix)
    # Check .env file configuration

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

MIT License - see LICENSE file for details.

Support


Built with ❤️ for the Tron developer community