Solidity is the most widely used programming language for writing smart contracts on blockchains that are compatible with the Ethereum Virtual Machine (EVM). Since EGC Blockchain is fully EVM-compatible, everything you learn in Solidity applies directly here.
If you’ve worked with JavaScript, Python, or Java, you’ll find Solidity familiar but with some blockchain-specific features. Once a smart contract is deployed, it becomes immutable (cannot be changed), making correctness and security very important.
Prerequisites
Accounts → Accounts on EGC (EOAs vs. Contract accounts): https://docs.eaglecoin.ai/developer-docs/foundation/accounts-on-egc-chain
Transactions → Transactions on EGC : https://docs.eaglecoin.ai/developer-docs/transactions
EVM Basics → How code executes on EGC Chain: https://docs.eaglecoin.ai/developer-docs/introduction-of-evm-and-opcodes
Solidity Basics
Smart Contract Structure
Every Solidity contract has three main parts:
State Variables → store data on-chain permanently
Functions → define logic to read/write data
Events → notify off-chain applications
First Example: Hello MST
Helloegc.sol
// SPDX-License-Identifier: MITpragmasolidity^0.8.0;contract HelloMST{stringpublic message ="Hello, MST Blockchain!";// Read function (free to call)functiongetMessage()publicviewreturns(stringmemory){return message;}// Write function (costs gas)functionsetMessage(stringcalldatanewMessage)public{ message = newMessage;}}
Key Points
pragma solidity ^0.8.0; → tells compiler version
public → variable is auto-readable without extra code
view → function does not cost gas (read-only)
Writing functions (like setMessage) cost gas
Data Types
uint / int → whole numbers (uint256 most common)
bool → true/false
address → represents wallets & contracts
string / bytes → text or raw binary data
mapping → key-value store (like hashmaps)
Example:
Functions
Functions are the heart of Solidity contracts.
view → reads blockchain state
pure → does not read/write state (math only)
payable → accepts EGC (native coin)
Example:
Control Structures
Solidity supports if, else, for, while, and require.
Example:
Building a Simple Token
A basic token contract that runs on EGC Blockchain:
Now you’ve created your own token on EGC Chain.
Deploying on EGC Blockchain (Step-by-Step)
1
Option: Using Remix IDE (Beginner-Friendly)
Go to Remix IDE: https://remix.ethereum.org/
Create a new file egccoin.sol and paste the contract
Compile with 0.8.x compiler
Switch MetaMask network to EGC Testnet (RPC + Chain ID)
In Remix, select Injected Web3 and connect MetaMask
Deploy contract → approve transaction in MetaMask
Copy contract address → you can now interact with it
2
Option: Using Hardhat (For Developers)
Install Hardhat:
Create a project:
Add MST RPC to hardhat.config.js:
Write your contract in contracts/ folder
Compile & deploy:
Best Practices
Always use the latest stable compiler (^0.8.x)
Use require() for input validation
Emit events for important actions
Avoid unnecessary storage writes (to save gas)
Audit contracts before mainnet deployment
References & Learning Resources
Official Solidity Docs: https://docs.soliditylang.org/
uint256 public count = 0;
bool public isActive = true;
address public owner;
mapping(address => uint256) public balances;
functions.sol
function add(uint256 a, uint256 b) public pure returns (uint256) {
return a + b;
}
function deposit() public payable {
balances[msg.sender] += msg.value;
}
withdraw.sol
function withdraw(uint amount) public {
require(balances[msg.sender] >= amount, "Not enough balance");
balances[msg.sender] -= amount;
payable(msg.sender).transfer(amount);
}
MSTCoin.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MSTCoin {
string public name = "MSTCoin";
string public symbol = "MSTC";
uint8 public decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
event Transfer(address indexed from, address indexed to, uint256 value);
constructor(uint256 _supply) {
totalSupply = _supply * 10**uint256(decimals);
balanceOf[msg.sender] = totalSupply; // assign all tokens to deployer
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(balanceOf[msg.sender] >= _value, "Not enough balance");
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
}