This repository serves as a tutorial and demonstration for Sunhat, a Hardhat-based development environment for TRON and EVM-compatible smart contracts.
Before you begin, ensure you have the following prerequisites installed on your system.
-
Node.js: Version
22.14.0or higher. -
pnpm: Version
10.6.5or higher.npm install -g pnpm
-
Foundry: A smart contract development toolchain.
# Install Foundry curl -L https://foundry.paradigm.xyz | bash # Set Foundry to the nightly channel foundryup --install nightly
First, clone this repository and install the necessary dependencies, including Hardhat and Sunhat.
# Clone the repository (replace with your URL)
git clone https://github.com/your-username/sunhat-demo.git
cd sunhat-demo
# Install dependencies
pnpm installExport you private key of the deployer account.
# env
PRIVATE_KEY=YOUR_PRIVATE_KEY_HEREThe hardhat.config.ts file is the central place to manage your project's settings.
You can configure multiple versions of the Solidity and Vyper compilers.
// hardhat.config.ts
solidity: {
compilers: [ // An array for different Solidity versions
{ version: "0.8.23", settings: { /* ... */ } },
{ version: "0.8.22", settings: { /* ... */ } },
]
},
vyper: {
compilers: [ // An array for different Vyper versions
{ version: "0.2.8" },
{ version: "0.3.10" }
]
}Define the networks for deployment and testing. The configuration below includes TRON's Nile testnet, Sepolia, and a local node.
// hardhat.config.ts
networks: {
localhost: {
live: false,
saveDeployments: true,
tags: ["local"],
deploy: ['deploy/'],
},
tron: {
url: "https://nile.trongrid.io/jsonrpc",
tron: true, // Required for TRON networks
deploy: ['deployTron/'],
accounts: [`${process.env.PRIVATE_KEY}`],
},
sepolia: {
url: "https://sepolia.drpc.org",
tron: false,
deploy: ['deploy/'],
accounts: [`${process.env.PRIVATE_KEY}`],
}
}-
tronSolc Support: Enable this if you are using the
tronSolccompiler.tronSolc: { enable: true, }
-
Named Accounts: Assign names to accounts for easy reference in scripts and tests.
namedAccounts: { deployer: { default: 0, // The first account is assigned as 'deployer' } }
Compile all source code in the contracts/ directory.
pnpm compileThis project supports testing with both Hardhat and Foundry.
Run the test files located in the test/ directory.
npx hardhat testor use the npm script:
npm run testFirst, initialize Foundry within the project, then run the tests.
# Initialize Foundry
npm run init-foundry
# Run Foundry tests
npm run test-foundryDeployment scripts are located in the deploy/ (for EVM) and deployTron/ (for TRON) directories.
To deploy, run the following command, specifying the target network:
npx hardhat deploy --network {network_name} --tags {tag_name}Alternatively, you can use the predefined npm scripts:
# Deploy to the TRON network (as configured)
npm run deploy-tron
# Deploy to an EVM-compatible network (as configured)
npm run deployAfter a successful deployment, artifacts containing the contract address and ABI are saved to deployments/{network_name}/{ContractName}.json.