Rise In Logo

Solidity Fundamentals

In this final part of the tutorial, you will be finalizing your Proposal Contract.

Let's start with a function to terminate a proposal.

function teminateProposal() external onlyOwner active {
    proposal_history[counter].is_active = false;

This function terminates the current proposal. It can only be called by the owner of the contract and the current proposal should be active to run this function which is indicated by active modifier.

Now, you will implement 3 query functions to retrieve data from the blockchain. Remember, the person/contract that call a query function does not pay gas fees.

  • The following function, will retrieve the information whether a given address has voted or not.
  • To figure this out, you will iterate through voted_addresses array and look for any matches with the given address parameter. Here is the implementation:
function isVoted(address _address) public view returns (bool) {
    for (uint i = 0; i < voted_addresses.length; i++) {
        if (voted_addresses[i] == _address) {
            return true;
    return false;
  • Next, you will implement a basic getter function to retrieve the current proposal:
function getCurrentProposal() external view returns(Proposal memory) {
    return proposal_history[counter];

Memory refers to a temporary location where data can be stored. It's erased between (external) function calls and is cheaper to use than storage. You may think it as the RAM of the EVM.

  • Finally, let's implement our a function to get a specific proposal:
function getProposal(uint256 number) external view returns(Proposal memory) {
    return proposal_history[number];

Congrulations, now you can look through the window thinking how did you became a smart contract developer!

On the next page, you can find the full contract ✌️

Rise In Logo

Rise together in web3