Solidity - Voting with a Smart Contract Part 1

in #dunkpay6 years ago (edited)

If you see news from around you, you'll see ads that you can vote with cryptocurrency.

To be used in voting , It should be easy for everyone to understand.
Can it be easily implemented?

As Korean election day is approaching, I have created a smart contract to vote.

https://ropsten.etherscan.io/address/0x6443e0136b122f2307db969d1adc939d3b14a57f#code

First, we elect two virtual candidates.

        setCandidate(0,"Kim","Keep The Rule!");
        setCandidate(1,"Lee","Be Free!");


Ms.Kim is a candidate who places importance on rules, Mr.Lee is a candidate who likes freedom.

        for (uint i=0; i< 50; i++) {
            uint8 randomNumber = random(i);
            if(randomNumber > 0){
                setVote(1, 1000 + i);
            }else
            {
                setVote(0, 1000 + i);
            }
        }


I tried to vote for 50 times with random function and visualize the data.

Screen Shot 2018-06-09 at 8.56.22 PM.png

https://www.dunkpay.com/vote-test/

When i use a random function, i can see that they get vote rating evenly.

After that, I thought about the case with the absent voters that did not like the two candidates.

        setCandidate(2,"N/A","I HATE DHEM.");


Run the Smart Contract to add it.

I will take a new vote now to see if it works..

Screen Shot 2018-06-09 at 9.47.46 PM.png

Press the button at the bottom to execute the contract.

        setVote(2, 1111); 

Screen Shot 2018-06-09 at 9.11.32 PM.png

https://ropsten.etherscan.io/tx/0x509fff804b98a6db51af9709aeba1b4eb0fcf676a62c04d019deb6af80a912a1

After the voting contract has been executed, you can confirm that the voting data has been properly reflected in the 50th column.

I hope that this contract will actually be introduced so that candidates who do not make commitments can be excluded in real world.

Can I use it in the presidential election? Unfortunately, Solidity only accepts uploads less than 2 gigabytes per contract address. (There is room for improvement.)

In this example, it is possible that duplicate voting is allowed and that the voter's information is open to everyone and is an incomplete voting contract.

As always, I will try to improve the problem next time ~

Please vote for:

https://wwwdunkpay.com/vote-test/

Sort:  

Congratulations @bitcoinyo! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @bitcoinyo! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.20
TRX 0.19
JST 0.034
BTC 91017.04
ETH 3083.40
USDT 1.00
SBD 2.87