Even Numbers Filter - Solidity Typing CST Test
Loading…
Even Numbers Filter — Solidity Code
Returns even numbers from an array.
pragma solidity ^0.8.0;
contract EvenNumbers {
uint[10] public nums = [1,2,3,4,5,6,7,8,9,10];
uint[] public evens;
function filter() public {
delete evens;
for(uint i=0;i<nums.length;i++) {
if(nums[i] % 2 == 0) {
evens.push(nums[i]);
}
}
}
}Solidity Language Guide
Solidity is a statically typed, contract-oriented programming language designed for building smart contracts on the Ethereum blockchain. It enables developers to write decentralized applications (dApps), manage digital assets, and automate trustless logic using a syntax inspired by JavaScript, C++, and Python.
Primary Use Cases
- ▸Smart contract development
- ▸DeFi protocols (DEXs, lending, staking)
- ▸NFT standards (ERC-721, ERC-1155)
- ▸Token creation (ERC-20)
- ▸DAO governance mechanisms
- ▸Permissioned enterprise blockchain apps
Notable Features
- ▸Contract-oriented design
- ▸Strong static typing
- ▸Events for EVM logs
- ▸Function modifiers
- ▸Library & inheritance support
Origin & Creator
Solidity was created by Gavin Wood and the Ethereum Foundation in 2014 to serve as the primary language for writing smart contracts on the Ethereum blockchain.
Industrial Note
Solidity is heavily used in decentralized finance (DeFi), NFT marketplaces, blockchain gaming, DAOs, tokenization engines, supply chain tracking, on-chain governance, and enterprise blockchain automation.
Quick Explain
- ▸Solidity compiles to EVM bytecode and runs on Ethereum nodes.
- ▸It powers smart contracts that govern DeFi, NFTs, DAOs, identity systems, and decentralized automation.
- ▸Supports inheritance, modifiers, events, libraries, interfaces, and blockchain-specific features like address types and payable functions.
Core Features
- ▸Contracts, interfaces, abstract contracts
- ▸Mappings, structs, arrays
- ▸Events & logs
- ▸Fallback & receive functions
- ▸Error handling: require, revert, assert
Learning Path
- ▸Learn Ethereum basics
- ▸Understand smart contract structure
- ▸Master storage, ABI, and gas
- ▸Build DeFi/NFT prototypes
- ▸Learn contract security & audits
Practical Examples
- ▸Create ERC-20 token
- ▸Deploy NFT contract
- ▸Build a decentralized marketplace
- ▸Create DAO governance contract
- ▸Develop DeFi staking protocol
Comparisons
- ▸Solidity vs Rust (Solana): EVM vs non-EVM
- ▸Solidity vs Vyper: syntax & security differences
- ▸Solidity vs Move (Sui/Aptos): resource model
- ▸Solidity vs JavaScript: on-chain vs off-chain logic
- ▸Solidity vs Python: static vs dynamic
Strengths
- ▸Native support for Ethereum standards
- ▸Large community & ecosystem
- ▸Powerful for financial logic
- ▸Extensive tooling (Hardhat, Foundry, Truffle)
- ▸Rich developer resources
Limitations
- ▸Security vulnerabilities are common
- ▸Gas-cost constraints
- ▸Upgradability complexity
- ▸Difficult debugging across chains
- ▸Blockchain immutability adds risk
When NOT to Use
- ▸Off-chain computation
- ▸High-storage applications
- ▸Real-time processing
- ▸Complex data analytics
- ▸Systems needing mutable logic
Cheat Sheet
- ▸uint public x;
- ▸mapping(address => uint) balances;
- ▸require(condition, 'Error');
- ▸emit EventName(param);
- ▸transfer, send, call for ETH transfers
FAQ
- ▸Is Solidity only for Ethereum?
- ▸No - it works on all EVM-compatible chains.
- ▸Is Solidity hard to learn?
- ▸Moderate - but security makes it challenging.
- ▸How do I debug smart contracts?
- ▸Using Hardhat console, traces, and tests.
- ▸Is Solidity secure?
- ▸Yes if coded & audited properly; otherwise risky.
30-Day Skill Plan
- ▸Week 1: Syntax, variables, functions
- ▸Week 2: Mappings, structs, modifiers, events
- ▸Week 3: ERC standards & DeFi patterns
- ▸Week 4: Gas optimization & security
Final Summary
- ▸Solidity is the core language for Ethereum smart contracts.
- ▸Used for DeFi, NFTs, DAOs, and enterprise blockchain automation.
- ▸Requires strong focus on gas efficiency and security.
- ▸Ecosystem-rich and essential for Web3 developers.
Project Structure
- ▸contracts/
- ▸scripts/
- ▸test/
- ▸deploy/
- ▸artifacts/build-info/
Monetization
- ▸Smart contract auditing
- ▸DeFi protocol development
- ▸NFT marketplace engineering
- ▸Blockchain freelancing
- ▸Enterprise blockchain consulting
Productivity Tips
- ▸Use Hardhat tasks
- ▸Automate tests
- ▸Use OpenZeppelin templates
- ▸Rely on security checkers
- ▸Reuse battle-tested libraries
Basic Concepts
- ▸Contracts & state variables
- ▸Functions (public, private, external)
- ▸Mappings, arrays, structs
- ▸Modifiers & events
- ▸ABI encoding & gas
Official Docs
- ▸Solidity Documentation
- ▸Ethereum Yellow Paper
- ▸EVM Opcodes Reference