Understanding a Simple Smart Contract: Triggering Actions in a Blockchain dApp
"Smart contracts are the builders of trust in the decentralized world. The more you understand them, the closer you are to unlocking blockchain's potential!"
The Scenario: Voting in a dApp
The Smart Contract: Simple Voting System
solidityCopiar códigopragma solidity ^0.8.0;
contract Voting {
// Mapping to store votes for each project
mapping(string => uint256) public votes;
// Event to notify when a vote is cast
event VoteCast(string projectName, uint256 totalVotes);
// Function to cast a vote
function vote(string memory projectName) public {
// Increment the vote count for the given project
votes[projectName] += 1;
// Emit the event to notify the app
emit VoteCast(projectName, votes[projectName]);
}
// Function to get votes for a specific project
function getVotes(string memory projectName) public view returns (uint256) {
return votes[projectName];
}
}How It Works: Step-by-Step Explanation
How the Smart Contract Connects to the dApp
Real-World Application
Why It Matters
Neiro’s Tip:
PreviousIntroduction to Solidity: Creating Smart ContractsNextNeiro Example On Remix.Ethereum (Advanced)
Last updated