APE Price: $0.71 (+0.10%)

Contract

0x16115d474AF482591d5c15B0536B9bc559590a51

Overview

APE Balance

Apechain LogoApechain LogoApechain Logo0 APE

APE Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
End Vote49192782024-11-21 20:51:5387 days ago1732222313IN
0x16115d47...559590a51
0 APE0.001125725.42069
Vote49094872024-11-21 18:40:4587 days ago1732214445IN
0x16115d47...559590a51
0 APE0.0017750225.42069

Parent Transaction Hash Block From To
View All Internal Transactions

Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Voting

Compiler Version
v0.8.27+commit.40a35a09

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 1 : Voting.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

contract Voting {

//@author chimmykk
// a smart contract to vote for Kamala and trump
    // Define candidates
    enum Candidate { Trump, Kamala }

    // Mapping to store votes for each candidate
    mapping(Candidate => uint256) public votes;

    // Mapping to track if an address has already voted
    mapping(address => bool) public hasVoted;

    // Variable to check if voting has ended
    bool public votingEnded;

    // Events to log the voting action
    event Voted(address indexed voter, Candidate candidate);
    event VotingEnded();

    // Constructor to initialize the contract
    constructor() {
        votingEnded = false;
    }

    // Function to vote for a candidate
    function vote(Candidate candidate) public {
        require(!votingEnded, "Voting has ended.");
        require(!hasVoted[msg.sender], "You have already voted.");
        
        // Mark this address as voted
        hasVoted[msg.sender] = true;

        // Increment the vote count for the selected candidate
        votes[candidate] += 1;

        // Emit an event for logging
        emit Voted(msg.sender, candidate);
    }

    // Function to get the vote count for a candidate
    function getVotes(Candidate candidate) public view returns (uint256) {
        return votes[candidate];
    }

    // Function to end the voting process
    function endVote() public {
        require(!votingEnded, "Voting has already ended.");
        votingEnded = true;

        // Emit an event for logging
        emit VotingEnded();
    }

    // Function to get the winner
    function getWinner() public view returns (string memory) {
        require(votingEnded, "Voting has not ended yet.");

        if (votes[Candidate.Trump] > votes[Candidate.Kamala]) {
            return "Trump wins!";
        } else if (votes[Candidate.Trump] < votes[Candidate.Kamala]) {
            return "Kamala wins!";
        } else {
            return "It's a tie!";
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"voter","type":"address"},{"indexed":false,"internalType":"enum Voting.Candidate","name":"candidate","type":"uint8"}],"name":"Voted","type":"event"},{"anonymous":false,"inputs":[],"name":"VotingEnded","type":"event"},{"inputs":[],"name":"endVote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum Voting.Candidate","name":"candidate","type":"uint8"}],"name":"getVotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getWinner","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"hasVoted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum Voting.Candidate","name":"candidate","type":"uint8"}],"name":"vote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum Voting.Candidate","name":"","type":"uint8"}],"name":"votes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"votingEnded","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]

6080604052348015600f57600080fd5b506002805460ff191690556105f7806100296000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80639d5a05291161005b5780639d5a0529146100f0578063b3f98adc146100fd578063b922394614610112578063c1b433571461011a57600080fd5b806309eef43e146100825780638953bb72146100ba5780638e7ea5b2146100db575b600080fd5b6100a56100903660046104bd565b60016020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b6100cd6100c83660046104ed565b61013a565b6040519081526020016100b1565b6100e3610178565b6040516100b1919061050e565b6002546100a59060ff1681565b61011061010b3660046104ed565b6102ed565b005b610110610432565b6100cd6101283660046104ed565b60006020819052908152604090205481565b60008060008360018111156101515761015161055c565b60018111156101625761016261055c565b8152602001908152602001600020549050919050565b60025460609060ff166101d25760405162461bcd60e51b815260206004820152601960248201527f566f74696e6720686173206e6f7420656e646564207965742e0000000000000060448201526064015b60405180910390fd5b600060208190527fada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d549080527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb554111561024c575060408051808201909152600b81526a5472756d702077696e732160a81b602082015290565b600060208190527fada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d549080527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb55410156102c7575060408051808201909152600c81526b4b616d616c612077696e732160a01b602082015290565b5060408051808201909152600b81526a497427732061207469652160a81b602082015290565b60025460ff16156103345760405162461bcd60e51b81526020600482015260116024820152702b37ba34b733903430b99032b73232b21760791b60448201526064016101c9565b3360009081526001602052604090205460ff16156103945760405162461bcd60e51b815260206004820152601760248201527f596f75206861766520616c726561647920766f7465642e00000000000000000060448201526064016101c9565b3360009081526001602081905260408220805460ff191682179055908083838111156103c2576103c261055c565b60018111156103d3576103d361055c565b815260200190815260200160002060008282546103f09190610572565b909155505060405133907f14075e33dffdc00c1fcaf75d0f86d667170be57fb566b12b41b499e5fa53b12590610427908490610599565b60405180910390a250565b60025460ff16156104855760405162461bcd60e51b815260206004820152601960248201527f566f74696e672068617320616c726561647920656e6465642e0000000000000060448201526064016101c9565b6002805460ff191660011790556040517f7a19ed057db79e3c2fa0b97a54b43bef4fce74b31bb6c01af514b9a18a7f70ab90600090a1565b6000602082840312156104cf57600080fd5b81356001600160a01b03811681146104e657600080fd5b9392505050565b6000602082840312156104ff57600080fd5b8135600281106104e657600080fd5b602081526000825180602084015260005b8181101561053c576020818601810151604086840101520161051f565b506000604082850101526040601f19601f83011684010191505092915050565b634e487b7160e01b600052602160045260246000fd5b8082018082111561059357634e487b7160e01b600052601160045260246000fd5b92915050565b60208101600283106105bb57634e487b7160e01b600052602160045260246000fd5b9190529056fea2646970667358221220c44dc9fa145b8c8a95c62261654873c07fbf9f5c0fbd9dad6d8861c4d4f07c4b64736f6c634300081b0033

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061007d5760003560e01c80639d5a05291161005b5780639d5a0529146100f0578063b3f98adc146100fd578063b922394614610112578063c1b433571461011a57600080fd5b806309eef43e146100825780638953bb72146100ba5780638e7ea5b2146100db575b600080fd5b6100a56100903660046104bd565b60016020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b6100cd6100c83660046104ed565b61013a565b6040519081526020016100b1565b6100e3610178565b6040516100b1919061050e565b6002546100a59060ff1681565b61011061010b3660046104ed565b6102ed565b005b610110610432565b6100cd6101283660046104ed565b60006020819052908152604090205481565b60008060008360018111156101515761015161055c565b60018111156101625761016261055c565b8152602001908152602001600020549050919050565b60025460609060ff166101d25760405162461bcd60e51b815260206004820152601960248201527f566f74696e6720686173206e6f7420656e646564207965742e0000000000000060448201526064015b60405180910390fd5b600060208190527fada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d549080527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb554111561024c575060408051808201909152600b81526a5472756d702077696e732160a81b602082015290565b600060208190527fada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d549080527fad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb55410156102c7575060408051808201909152600c81526b4b616d616c612077696e732160a01b602082015290565b5060408051808201909152600b81526a497427732061207469652160a81b602082015290565b60025460ff16156103345760405162461bcd60e51b81526020600482015260116024820152702b37ba34b733903430b99032b73232b21760791b60448201526064016101c9565b3360009081526001602052604090205460ff16156103945760405162461bcd60e51b815260206004820152601760248201527f596f75206861766520616c726561647920766f7465642e00000000000000000060448201526064016101c9565b3360009081526001602081905260408220805460ff191682179055908083838111156103c2576103c261055c565b60018111156103d3576103d361055c565b815260200190815260200160002060008282546103f09190610572565b909155505060405133907f14075e33dffdc00c1fcaf75d0f86d667170be57fb566b12b41b499e5fa53b12590610427908490610599565b60405180910390a250565b60025460ff16156104855760405162461bcd60e51b815260206004820152601960248201527f566f74696e672068617320616c726561647920656e6465642e0000000000000060448201526064016101c9565b6002805460ff191660011790556040517f7a19ed057db79e3c2fa0b97a54b43bef4fce74b31bb6c01af514b9a18a7f70ab90600090a1565b6000602082840312156104cf57600080fd5b81356001600160a01b03811681146104e657600080fd5b9392505050565b6000602082840312156104ff57600080fd5b8135600281106104e657600080fd5b602081526000825180602084015260005b8181101561053c576020818601810151604086840101520161051f565b506000604082850101526040601f19601f83011684010191505092915050565b634e487b7160e01b600052602160045260246000fd5b8082018082111561059357634e487b7160e01b600052601160045260246000fd5b92915050565b60208101600283106105bb57634e487b7160e01b600052602160045260246000fd5b9190529056fea2646970667358221220c44dc9fa145b8c8a95c62261654873c07fbf9f5c0fbd9dad6d8861c4d4f07c4b64736f6c634300081b0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.