π§ͺ A dual-blockchain development toolkit built with Scaffold-ETH 2 for both Ethereum and Tron networks. This toolkit makes it easier for developers to create and deploy smart contracts on both blockchains and build user interfaces that interact with those contracts.
βοΈ Built using NextJS, RainbowKit, Hardhat, Wagmi, Viem, TronBox, TronWeb, and Typescript.
- β Contract Hot Reload: Your frontend auto-adapts to your smart contract as you edit it.
- πͺ Custom hooks: Collection of React hooks wrapper around wagmi to simplify interactions with smart contracts with typescript autocompletion.
- π§± Components: Collection of common web3 components to quickly build your frontend.
- π₯ Burner Wallet & Local Faucet: Quickly test your application with a burner wallet and local faucet.
- π Integration with Wallet Providers: Connect to different wallet providers and interact with the Ethereum network.
- π TronBox Integration: Deploy smart contracts to Tron networks (Shasta, Nile, Mainnet)
- π Account Management: Automated Tron account generation with QR codes
- π° Balance Checking: Real-time TRX balance monitoring across networks
- π§ͺ Testnet Support: Easy deployment and testing on Tron testnets
- β‘ TVM Compatibility: Leverage Tron Virtual Machine's EVM compatibility
- π Unified Components: Address and balance components that work seamlessly with both Ethereum and Tron
- π Copy Functionality: One-click copy for all address types with proper formatting
- π Block Explorer Links: Direct links to appropriate block explorers for each network
- βοΈ Unified Network Config: Configure both Ethereum and Tron networks in a single
scaffold.config.ts - π Network Switching: Easy switching between different Tron networks (Shasta, Nile, Mainnet)
- π― Target Network Selection: Set your preferred Tron network just like Ethereum networks
Understanding the fundamental differences between Tron and Ethereum is crucial for effective dual-blockchain development. While both networks support smart contracts and use similar development tools, they have distinct characteristics that affect how you build and deploy applications.
| Aspect | Ethereum | Tron |
|---|---|---|
| Consensus | Proof of Stake (PoS) | Delegated Proof of Stake (DPoS) |
| Block Time | ~12 seconds | ~3 seconds |
| TPS | ~15 transactions/second | ~2,000 transactions/second |
| Validators | Unlimited validators | 27 Super Representatives |
| Finality | Probabilistic | Near-instant |
Ethereum:
- Gas Model: Pay gas fees in ETH for all operations
- Variable Costs: Fees fluctuate based on network congestion
- Contract Deployment: Can cost $50-500+ depending on network conditions
Tron:
- Energy/Bandwidth Model: Three resource types:
- TRX: Native token for transactions
- Energy: Consumed by smart contract execution
- Bandwidth: Used for transaction data
- Free Daily Allowance: Users get free bandwidth daily
- Predictable Costs: More stable pricing, deployment typically costs 50-100 TRX (~$5-10)
// Ethereum addresses (20 bytes, hexadecimal)
0x742d35Cc6634C0532925a3b8D9C24A8c9A4c7c7b
// Tron addresses (21 bytes, Base58 encoded)
T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb
// Both can be used interchangeably in smart contracts
// Tron also supports hex format internallyEthereum:
// Standard deployment
contract MyContract {
constructor() {
// Initialization code
}
}Tron:
// Same Solidity code, but different execution context
contract MyContract {
constructor() {
// Initialization - executed on TVM (Tron Virtual Machine)
}
// Tron-specific considerations:
// - Lower gas costs for computation
// - Different opcodes for some operations
// - Energy instead of gas
}1. Transaction Types
- Ethereum: Simple transactions and contract calls
- Tron: 30+ transaction types (Transfer, TriggerSmartContract, CreateSmartContract, etc.)
2. Resource Management
// Ethereum: Gas estimation
uint256 gasRequired = estimateGas(functionCall);
// Tron: Energy consumption is more predictable
// Energy cost depends on instruction complexity, not network congestion3. Built-in Functions
// Tron has additional built-in functions:
// - freeze/unfreeze for staking
// - vote for Super Representatives
// - energy and bandwidth queriesSolidity Compatibility:
- Ethereum: Latest Solidity versions (0.8.x)
- Tron: TVM supports most Solidity features with some limitations:
- Some newer opcodes may not be available
- Different gas cost structure for operations
- Events and logs work similarly but with different indexing
Testing Differences:
// Ethereum testing (Hardhat)
describe("Contract", function () {
it("Should deploy and work", async function () {
const contract = await MyContract.deploy();
// Standard Web3.js/Ethers.js patterns
});
});
// Tron testing (TronBox + TronWeb)
describe("Contract", function () {
it("Should deploy and work", async function () {
const contract = await tronWeb.contract().new({
// TronWeb-specific deployment
});
// TronWeb has different API patterns
});
});Ethereum Ecosystem:
- Hardhat/Foundry: Development frameworks
- Web3.js/Ethers.js: JavaScript libraries
- MetaMask: Primary wallet integration
- Etherscan: Block explorer
Tron Ecosystem:
- TronBox: Development framework (similar to Truffle)
- TronWeb: JavaScript library (similar to Web3.js)
- TronLink: Primary wallet integration
- TronScan: Block explorer
Ethereum Networks:
// scaffold.config.ts
targetNetworks: [
chains.hardhat, // Local development
chains.sepolia, // Testnet
chains.mainnet, // Production
];Tron Networks:
// scaffold.config.ts
targetTronNetwork: tronShasta, // Testnet
// targetTronNetwork: tronNile, // Alternative testnet
// targetTronNetwork: tronMainnet, // ProductionEthereum:
- Higher security through decentralization
- Slower transaction finality
- More expensive operations
- Larger developer ecosystem
Tron:
- Faster transaction processing
- Lower transaction costs
- More centralized consensus
- Growing DeFi ecosystem
When porting contracts between networks:
- Gas β Energy: Review resource consumption patterns
- Address handling: Ensure proper address format conversion
- Event indexing: May require adjustments for different explorers
- Wallet integration: Different connection patterns (MetaMask vs TronLink)
- Testing: Network-specific test patterns and tools
For Dual-Chain Development:
- Write network-agnostic smart contracts when possible
- Use Scaffold-TRON's unified components for consistent UX
- Test thoroughly on both networks' testnets
- Consider cost implications when choosing primary network
- Implement proper error handling for network-specific features
Performance Tips:
- Ethereum: Optimize for gas efficiency, batch operations
- Tron: Leverage faster block times, utilize free bandwidth
- Both: Use events for indexing, implement proper access controls
This dual-blockchain approach gives you the best of both worlds: Ethereum's security and ecosystem with Tron's speed and low costs!
Before you begin, you need to install the following tools:
- Node (>= v20.18.3)
- Yarn (v1 or v2+)
- Git
- Clone the repository:
git clone https://github.com/kmjones1979/scaffold-tron.git tron-dapp- Install dependencies:
cd tron-dapp
yarn install- Configure your target networks in
packages/nextjs/scaffold.config.ts:
const scaffoldConfig = {
// Ethereum networks (existing)
targetNetworks: [chains.hardhat],
// Tron network (new!)
// Available options:
// - tronShasta: Shasta testnet (for development)
// - tronNile: Nile testnet (for development)
// - tronMainnet: Tron mainnet (for production)
targetTronNetwork: tronShasta,
// ... other config
};- Run a local Ethereum network:
yarn chain- Deploy Ethereum contracts:
yarn deploy- Start the NextJS frontend:
yarn startVisit your app on: http://localhost:3000. You can interact with your smart contract using the Debug Contracts page.
Generate Tron accounts for all networks (includes QR codes for easy wallet import):
yarn tron:setupThis creates accounts for:
- Shasta Testnet (primary for testing)
- Nile Testnet (alternative testnet)
- Mainnet (production)
- Development (local)
Get free TRX from faucets for testing:
Shasta Testnet Faucets:
- https://shasta.tronex.io/join/getJoinPage - Get 2000 test TRX
- https://www.trongrid.io/shasta/ - Alternative faucet
Nile Testnet Faucet:
Copy your Shasta testnet address from the setup output and request test TRX.
yarn tron:balanceThis shows real-time balances for all your Tron accounts.
yarn tron:compileDeploy to Shasta Testnet:
yarn tron:deploy:testnetDeploy to Nile Testnet:
yarn tron:deploy:nileDeploy to Mainnet (requires real TRX):
yarn tron:deploy:mainnetyarn tron:testTests run against the Shasta testnet to verify contract functionality.
The UnifiedAddress component automatically detects and handles both Ethereum and Tron addresses:
import { UnifiedAddress } from "~~/components/scaffold-eth";
// Works with both Ethereum (0x...) and Tron (T...) addresses
<UnifiedAddress
address="T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb"
format="short"
size="base"
/>;Features:
- β Auto-detection: Automatically detects address type
- π Copy functionality: One-click copy for all addresses
- π Block explorer links: Direct links to appropriate explorers
- π¨ Consistent styling: Matches Ethereum address styling
- π± Responsive design: Works across all screen sizes
Configure your preferred Tron network in scaffold.config.ts:
// For development
targetTronNetwork: tronShasta,
// For production
targetTronNetwork: tronMainnet,The entire application will automatically use your configured network!
yarn chain- Start local Ethereum networkyarn deploy- Deploy to local Ethereum networkyarn start- Start NextJS frontendyarn hardhat:test- Run Ethereum contract tests
yarn tron:setup- Generate Tron accounts with QR codesyarn tron:account- Display account informationyarn tron:balance- Check TRX balances across networksyarn tron:compile- Compile contracts for Tronyarn tron:deploy:testnet- Deploy to Shasta testnetyarn tron:deploy:nile- Deploy to Nile testnetyarn tron:deploy:mainnet- Deploy to Tron mainnetyarn tron:test- Run Tron contract testsyarn tron:console- Open TronBox console
-
Shasta Testnet: Primary testing network
- Explorer: https://shasta.tronscan.org
- Faucets: Shasta Faucet 1 | Shasta Faucet 2
-
Nile Testnet: Alternative testing network
- Explorer: https://nile.tronscan.org
- Faucet: Nile Faucet
-
Mainnet: Production network
- Explorer: https://tronscan.org
- Requires real TRX from exchanges
tron-dapp/
βββ packages/
β βββ hardhat/ # Ethereum & Tron smart contracts
β β βββ contracts/ # Solidity contracts (compatible with both chains)
β β βββ deploy/ # Ethereum deployment scripts
β β βββ tron-migrations/ # Tron deployment scripts
β β βββ test/ # Ethereum tests
β β βββ tron-test/ # Tron tests
β β βββ scripts/ # Utility scripts for Tron
β β βββ hardhat.config.ts # Ethereum configuration
β β βββ tronbox.js # Tron configuration
β βββ nextjs/ # Frontend application
β βββ app/ # Next.js app router
β βββ components/ # React components
β β βββ scaffold-eth/ # Enhanced components
β β βββ UnifiedAddress.tsx # Unified address component
β β βββ UnifiedBalance.tsx # Unified balance component
β β βββ UnifiedConnectButton.tsx # Dual-blockchain connect button
β βββ hooks/ # Custom React hooks
β β βββ scaffold-eth/ # Enhanced hooks
β β βββ useTronReadContract.ts # Tron contract reading
β β βββ useTronWriteContract.ts # Tron contract writing
β β βββ useUnifiedWriteContract.ts # Unified contract interactions
β βββ services/ # Web3 services
β β βββ web3/ # Web3 providers
β β βββ tronConfig.tsx # Tron provider
β β βββ unifiedWeb3Context.tsx # Unified Web3 context
β βββ scaffold.config.ts # Unified network configuration
- Unified Config:
packages/nextjs/scaffold.config.ts- Configure both Ethereum and Tron networks - Ethereum:
packages/hardhat/hardhat.config.ts- Ethereum-specific configuration - Tron:
packages/hardhat/tronbox.js- Tron-specific configuration - Environment:
packages/hardhat/.env- Auto-generated by setup
// packages/nextjs/scaffold.config.ts
import {
tronShasta,
tronNile,
tronMainnet,
} from "~~/utils/scaffold-eth/networks";
const scaffoldConfig = {
// Ethereum networks
targetNetworks: [chains.hardhat],
// Tron network selection
targetTronNetwork: tronShasta, // Easy to change!
// Other configuration...
};- Use
yarn chainfor local development - Deploy contracts with
yarn deploy - Test with
yarn hardhat:test
- Always fund testnet accounts before deploying
- Use
yarn tron:balanceto check funding status - Test on Shasta testnet before mainnet deployment
- Contract deployment costs ~50-100 TRX on testnets
- Smart contracts are compatible with both Ethereum and Tron
- Same Solidity code deploys to both networks
- Use network-specific tools for deployment and testing
- Configure target networks in
scaffold.config.ts - Use
UnifiedAddresscomponent for consistent address display
- Use
UnifiedAddressinstead ofAddressfor better Tron support - Configure your preferred Tron network in scaffold config
- Test address copying and block explorer links
- Ensure proper network switching in your dApp
- π¨ Rebranded to Scaffold-TRON with proper Scaffold-ETH attribution
- βοΈ Unified Configuration: Configure Tron networks in
scaffold.config.ts - π Enhanced Components: Improved UnifiedAddress with copy functionality and block explorer links
- π± Better UX: Consistent address formatting and interaction patterns
- ποΈ Component Renaming: Updated internal component names for consistency
- π Network Utilities: Added
getTargetTronNetwork()utility function
- Scaffold-ETH 2 Docs - Learn about the original framework
- Scaffold-ETH 2 Website - Feature overview
- TronBox Documentation - Tron development toolkit
- TronWeb API - Tron JavaScript SDK
- Tron Developer Hub - Complete Tron development resources
We welcome contributions to Scaffold-TRON!
Please see CONTRIBUTING.MD for more information and guidelines for contributing to Scaffold-ETH 2.
- Configure your networks in
scaffold.config.ts - Deploy your contracts to both Ethereum and Tron testnets
- Test extensively using the provided test suites
- Build your frontend using the enhanced Scaffold-TRON components
- Go multi-chain by deploying to production networks
Happy building! π
Built with β€οΈ on Scaffold-ETH 2
