Smart Contract
JuChain currently supports Solidity versions <= 0.8.8 for compilation. Support for later versions will be gradually introduced based on official announcements.
JuChain is fully compatible with the Ethereum Virtual Machine (EVM), enabling developers to seamlessly deploy and execute smart contracts written in Solidity. This document provides an introduction to the essentials of smart contract development on JuChain.
Contract Development
Development Environment
To develop smart contracts on JuChain, you’ll need:
Code Editor: Tools like VSCode or Remix.
Solidity Compiler: For compiling your Solidity code.
Web3 Development Framework: Options include Hardhat or Truffle.
JuChain RPC Endpoint: To connect to the JuChain network (e.g.,
https://testnet-rpc.juchain.org
for testnet).
Contract Deployment
You can deploy smart contracts to JuChain using:
Remix IDE: Connect to the JuChain network via the “Injected Web3” provider (e.g., MetaMask configured with JuChain RPC).
Hardhat or Truffle: Use deployment scripts tailored to JuChain’s network settings.
Web3 Library: Interact directly with the network using libraries like Web3.js or ethers.js.
Example: Deploying with Hardhat
Configure Hardhat with JuChain’s network:
Best Practices
When developing smart contracts for JuChain:
Thorough Testing: Test contracts extensively using frameworks like Hardhat or Truffle to catch bugs early.
Security Practices: Follow guidelines like OpenZeppelin’s security recommendations to prevent vulnerabilities (e.g., reentrancy, overflow).
Gas Optimization: Minimize gas costs by optimizing loops, storage usage, and function calls.
Stable Solidity Version: Use the latest stable Solidity version supported by JuChain (currently <= 0.8.8).
Access Control: Implement role-based access (e.g., OpenZeppelin’s
Ownable
orAccessControl
) to restrict sensitive functions.
Example: Simple Contract with Access Control
Contract Verification
After deployment, verify your contract’s source code on JuChain’s block explorer (e.g., https://testnet.juscan.io
) for transparency and security. Verification ensures users can audit the deployed bytecode against the source.
Steps for Verification:
Flatten Contract: If using multiple files or imports, flatten your code into a single file (e.g., using
hardhat flatten
).Submit on Explorer: Provide the contract address, flattened source code, compiler version (e.g., 0.8.8), and constructor arguments (if any).
Confirm: Once verified, the explorer will display the contract’s source and ABI publicly.
Example: Hardhat Verification
Requires the Hardhat Etherscan plugin and an API key (if applicable).
Last updated