Experiment L TLC
Experiment L TLC
Applications in
Education
Smart Contracts and Cryptocurrency Simulations
Smart Contract Development
• 1. Tools: Remix IDE, Ganache, Truffle
• 2. Create a voting system:
• - Predefined candidates
• - Single vote per user
• 3. Advanced Features:
• - Voting period with timestamps
• - Real-time result updates
Sample Solidity Code
• pragma solidity ^0.8.0;
• contract Voting {
• struct Candidate {
• string name;
• uint voteCount;
• }
• mapping(address => bool) public hasVoted;
• Candidate[] public candidates;
• function addCandidate(string memory name) public {
• candidates.push(Candidate(name, 0));
• }
• function vote(uint candidateIndex) public {
• require(!hasVoted[msg.sender], 'Already voted');
• require(candidateIndex < candidates.length, 'Invalid candidate');
• hasVoted[msg.sender] = true;
• candidates[candidateIndex].voteCount++;
• }
• }
Simulating Cryptocurrency
Transactions
• 1. Tools: Ganache, MetaMask
• 2. Steps to simulate transactions:
• - Initialize accounts using Ganache
• - Deploy a wallet contract
• - Transfer ETH between accounts
• 3. Advanced Features:
• - Multi-signature wallets
• - Decentralized exchanges
Sample Solidity Code: Wallet
• pragma solidity ^0.8.0;
• contract SimpleWallet {
• mapping(address => uint) public balances;
• function deposit() public payable {
• balances[msg.sender] += msg.value;
• }
• function transfer(address payable to, uint amount) public {
• require(balances[msg.sender] >= amount, 'Insufficient balance');
• balances[msg.sender] -= amount;
• to.transfer(amount);
• }
• }