How a Blockchain-Based System Can Help Decide on Community Proposals

Matheus Leal
Geek Culture
Published in
6 min readJan 25, 2022

--

This article presents a solution for document validation and voting using Blockchain. Even with the world moving quickly, validation processes are often slow and manual. The use of Smart Contracts and Blockchain is ideal for this manual and unreliable scenario. Our decentralized system stores the history of assets and transactions on a network with no central point of failure. More resistant to malicious attacks, Blockchain allows the acceptance and vote of documents securely and digitally.

Retrive from The Gateway Digital

Introduction

You have this wonderful idea for a project. The more you research it, the more you think it’s something worth the funding and resources. It’s a potential game-changer, and if things work out the way you predict, the resulting product will be a win for the community. But how do you get the decision-makers to buy into your idea? The short answer: Prepare a convincing project proposal. But what if more than one person has a good idea? How can we safely and transparently choose the best one?

Blockchain can be of great help in scenarios that lack trust or a central validator. Blockchain is a network that runs with connected blocks through a hash that guarantees the security and immutability of information.

Our objective is to show a secure and transparent solution for an online voting system of proposals. A Blockchain-based system can help decide on community proposals. People can send proposals that later others can decide the best.

Proposal

By using this service, you will be able to vote on proposals sent as files. Here we refer to a proposal as a plan or suggestion, especially a formal or written one, put forward for consideration or discussion by others. To maintain data immutability, we store the files in a WORM (Write Once Read Many) systems. WORM describes a data storage device in which information, once written, cannot be modified. This writes protection affords the assurance that the data cannot be tampered with once it is written to the device. The system should guarantee the greatest equality and transparency. Because of this, we understand that the best way to create these systems would be through a Decentralized Application(DApps). This is an application that can operate autonomously, typically through the use of smart contracts, that runs on decentralized computing, a Blockchain system. Like traditional applications, DApps provide some function or utility to their users.

The best way to implement a proposal system that uses Blockchain technology would be to develop an API that interacts with Smart Contracts. Those are self-executing digital contracts that use technology to ensure that the agreements signed will be made. The validation of the contract rule is done through a Blockchain. This ensures that the contract cannot be changed and that there is no central validator. For this project, the assets are the documents and the transaction is the act of users voting on one of these proposals.

We think that it would be better to use a public Blockchain network where access is completely open. This means that everyone can receive and send transactions from anyone in the world. The possibility to be audited by anyone is valuable in a system that aims to validate a document. Among such networks, we understand that Ethereum would be the best option. It is the largest network that allows the use of Smart Contracts. Before a transaction can be considered valid, it must be authorized by each of its constituent nodes through the chain consensus process. This guarantees the greatest equality and transparency in the system.

Implementation

Our goal is to show a solution for validating and voting proposals in a transparent and inviolable way. We will create an API to interact with the proposals and the Ethereum network. This service is very simple. Using only the web3js package we were able to interact with the smart contract. Because of that, we are only going to show here how to implement a smart contract to verify documents at Ethereum. For that, we need to write the code in Solidity. This is an object-oriented programming language for writing smart contracts. It is used to implement smart contracts on various Blockchain platforms, most notably Ethereum. Let’s first define the struct that will represent each proposal of our voting contract.

// Data related with defining the winner proposal 
struct Proposal {
string file_name;
string file_id;
address sender;
}

file_name represents the visible name that facilitates the identification of the proposal. The address attribute represents the unique id that each network user has. The idea would be to store in file_id a hash of the proposal file that was sent and stored in a WORM database. This way we can guarantee that no following changes made on the database is valid. The hash will only be identical to the file stored the first time.

We need to have a function in the contract that gets people’s vote for a specific proposal. For this we have a map that stores each vote based on the proposal’s file_id. To ensure that no one can vote more than once on the same proposal, we have another boolean map to define this.

// Voting for a file 
function voteFile(string memory file_id) public payable {
if ( voteTransaction[msg.sender] == true )
return;
string memory transaction_sender = toString(msg.sender);// Set the transaction id and mark as voted string memory

transaction_id = string(abi.encodePacked(transaction_sender,file_id));
voteTransaction[msg.sender] = true; vote[file_id] = vote[file_id] + 1 + winValue[msg.sender];
}

We also need a function to define the most voted file. Unfortunately, we didn’t find a way to check this without a for loop. These types of interactions are quite costly for systems running on gas. This is the unit of account for computational work used to pass on the cost of every transaction to the user. More work equals more gas which costs more to execute. Imagine your CPU sent you a bill for every single operation. This function will be the most expensive to perform on the smart contract.

// Defining most voted file 
function winningProposal() public payable returns (string memory _winningProposal, address _winningAddress) {
uint256 winningVoteCount = 0;
address winningAdd;
for (uint8 prop = 0; prop < proposals.length; prop++){
string memory fn = proposals[prop].file_id;
if (vote[fn] > winningVoteCount) {
winningVoteCount = vote[fn]; winningAdd = proposals[prop].sender;
_winningProposal = fn; _winningAddress = winningAdd;
}
}
winValue[winningAdd] += 2;
return (_winningProposal, _winningAddress);
}

For the whole implementation please access our Github repository. There you will be able to find how we implemented the search for the proposals and also if someone has previously voted.

Conclusion

You have this wonderful idea for a project, it’s a potential game-changer, and if things work out the way you envision them, the resulting product will be a huge win for the organization, even for the industry as a whole. But what if more than one person has a good idea? How can we safely and transparently choose the best one? This article aims to present a proposal for document validation and voting using Blockchain. We will create an API to interact with the proposals and the Ethereum network. Wrote in Solidity, our smart contracts represent each proposal. The assets are the documents and the transaction is the act of users voting on one of these proposals. For the whole implementation please access our repository.

--

--

Matheus Leal
Geek Culture

M.Sc at Pontifícia Universidade Católica do Rio de Janeiro & Applying DevOps culture at Globo