Solidity : Smart Contract Programming Language
Introduction
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract HelloMST {
string public message = "Hello, MST Blockchain!";
// Read function (free to call)
function getMessage() public view returns (string memory) {
return message;
}
// Write function (costs gas)
function setMessage(string calldata newMessage) public {
message = newMessage;
}
}Key Points
pragma solidity ^0.8.0;→ tells compiler versionpublic→ variable is auto-readable without extra codeview→ function does not cost gas (read-only)Writing functions (like
setMessage) cost gas
Data Types
uint/int→ whole numbers (uint256most common)bool→ true/falseaddress→ represents wallets & contractsstring/bytes→ text or raw binary datamapping→ key-value store (like hashmaps)
Example:
Functions
Functions are the heart of Solidity contracts.
view→ reads blockchain statepure→ 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)
Option: Using Remix IDE (Beginner-Friendly)
Go to Remix IDE: https://remix.ethereum.org/
Create a new file
egccoin.soland paste the contractCompile with
0.8.xcompilerSwitch 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
Best Practices
Always use the latest stable compiler (
^0.8.x)Use
require()for input validationEmit 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/
Remix IDE: https://remix.ethereum.org/
Hardhat Docs: https://hardhat.org/
Truffle Suite: https://trufflesuite.com/
OpenZeppelin Contracts: https://docs.openzeppelin.com/contracts/ (prebuilt, audited smart contracts)
Ethereum Smart Contract Best Practices: https://consensys.github.io/smart-contract-best-practices/
This content was sourced from the original MST Blockchain docs. By browsing the EGC site you accept their privacy policy: https://eaglecoin.ai/privacy
Last updated