Smart Contract
Smart ContractAICChain currently supports Solidity versions <= 0.8.8 for compilation. Support for later versions will be gradually introduced based on official announcements.
AICChain 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 AICChain.
Contract Development
Development Environment
To develop smart contracts on AICChain, 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.
AICChain RPC Endpoint: To connect to the AICChain network (e.g., https://rpc.aicchain.io for testnet).
Contract Deployment
You can deploy smart contracts to AICChain using:
Remix IDE: Connect to the AICChain network via the “Injected Web3” provider (e.g., MetaMask configured with AICChain RPC).
Hardhat or Truffle: Use deployment scripts tailored to AICChain network settings.
Web3 Library: Interact directly with the network using libraries like Web3.js or ethers.js.
Example: Deploying with Hardhat
Configure Hardhat with AICChain network:
Best Practices
When developing smart contracts for AICChain:
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 AICChain (currently <= 0.8.8).
Access Control: Implement role-based access (e.g., OpenZeppelin’s
OwnableorAccessControl) to restrict sensitive functions.
Example: Simple Contract with Access Control
Contract Verification
After deployment, verify your contract’s source code on AICChain block explorer (e.g., https://scan.aicchain.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