sunhat

Sunhat

CI Status NPM Version License: MIT

An All-in-One Toolkit for the Complete TRON Smart Contract Lifecycle

Sunhat is a comprehensive Hardhat plugin designed to provide a seamless, end-to-end development experience on TRON. It manages every stage of your project—from writing code in multiple languages to deploying with confidence—all within a single, unified workflow.

What is it for?

This hardhat plugin adds a mechanism to deploy contracts to any network, Especially to Tron , keeping track of them and replicating the same environment for testing.

A Closed-Loop Lifecycle: Develop, Test, Deploy

Sunhat creates a complete, closed-loop process, ensuring consistency and reliability from the first line of code to the final on-chain transaction.

Core Features at a Glance


QuickStart

This guide walks you through setting up sunhat in a new project from scratch.

You can get a complete demo here


Installation

This guide walks you through installing sunhat from scratch.

Prerequisites

Install Sunhat

You can install Sunhat by executing the following command:

npm install -g @sun-protocol/sunhat

Install Optional Extensions

For Vyper compiler support:

Vyper Installation Guide

pip install vyper==0.2.8

For Foundry test support:

Foundry Installation Guide

# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
# Set Foundry to the nightly channel
foundryup --install nightly

Step 1: Configure Hardhat

Add sunhat to your hardhat.config.ts:

import { HardhatUserConfig } from '@sun-protocol/sunhat';

const config: HardhatUserConfig = {
  solidity: {
    compilers: [
      {
        version: '0.8.23',
        optimizer: {
          enabled: true, // enabled for optimizer
          runs: 999999, // runs time for optimizer run
        },
      },
    ],
  },
  // settings for different networks
  networks: {
    tron: {
      url: 'https://nile.trongrid.io/jsonrpc', // tron mainnet rpc url
      tron: true, // enable tron network
      deploy: ['deployTron/'], // folder for tron deploy scripts
      accounts: [`${process.env.PRIVATE_KEY}`], // account private key for deploy
    },
  },
};

export default config;

Step 2: Create Your First Contract

Create a simple contract in contracts/Lock.sol:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract Lock {
    uint public unlockTime;
    address payable public owner;

    event Withdrawal(uint amount, uint when);

    constructor(uint _unlockTime) payable {
        require(_unlockTime > block.timestamp, "Unlock time should be in the future");
        unlockTime = _unlockTime;
        owner = payable(msg.sender);
    }

    function withdraw() public {
        require(block.timestamp >= unlockTime, "You can't withdraw yet");
        require(msg.sender == owner, "You aren't the owner");
        emit Withdrawal(address(this).balance, block.timestamp);
        owner.transfer(address(this).balance);
    }
}

Step 3: Create Deploy Directory

Create a deployTron/ directory in your project root.


Step 4: Write Your First Deploy Script

Create deployTron/1.ts:

module.exports = async ({
  getNamedAccounts,
  deployments,
  getChainId,
  getUnnamedAccounts,
}) => {
  const {deploy} = deployments;
  const {deployer} = await getNamedAccounts();

  // the following will only deploy "GenericMetaTxProcessor" if the contract was never deployed or if the code changed since last deployment
  const res = await deploy('Lock', {
    from: deployer,
    gasLimit: 4000000,
    args: [1893456000],
    tags: 'lumi',
  });
  console.log(res)
};

module.exports.tags = ['lumi'];

Step 5: Compile and Deploy

Compile your contracts:

npx hardhat compile

Deploy to tron network:

npx hardhat --network tron deploy --tags lumi

Step 6: Verify Deployment

Check the deployments/ directory for your deployment files. You should see:

├── deployments
│   └── tron
│       └── Lock.json

IDE Skills Integration

Sunhat exposes a specialized Skills interface that acts as a “driver” for AI agents. By pointing your AI assistant to the skill definition in skills/sunhat/, you unlock expert-level capabilities for testing, deploying, and auditing TRON contracts autonomously.

skills/
└── sunhat/
    ├── SKILL.md            # Main entry point
    └── workflows/
        ├── sunhat-init.md
        ├── sunhat-compile.md
        ├── sunhat-test.md
        ├── sunhat-deploy.md
        └── sunhat-audit.md

Supported IDEs

IDE Setup
Claude Code Place skills/sunhat in project root. Claude auto-discovers SKILL.md.
Google Antigravity Place skills/sunhat in .agent/skills/sunhat. Antigravity auto-discovers SKILL.md.
OpenCode Place skills/sunhat in .opencode/skills/sunhat. OpenCode auto-discovers SKILL.md.
Cursor Copy SKILL.md content into .cursorrules or reference workflow paths.

Example Usage

# Claude Code
> "Run the tests for the Lock contract using Sunhat."

# Antigravity
> "Deploy the Token contract to Nile testnet."

The AI agent will discover the skill, read the appropriate workflow, and execute the task deterministically.


Development

To dive deeper into advanced topics of the sunhat project lifecycle, please see the Documentation for guides and reference.


How to Contribute

We welcome contributions from everyone! Contributions to sunhat are released under the terms of the MIT License. By submitting a pull request, you agree to license your contribution under this license.

To contribute, see CONTRIBUTE.md