0

I am planning to make a decentralized voting application. The addresses of eligible voters should be uploaded on IPFS for anyone to access.

This file on IPFS will be used in the contract to make sure that only eligible voters can vote.

The aim of this project is to use IPFS as a tool for verifying the eligible voters.

One way I can think of, is to put the addresses of eligible voters in a text file and upload on IPFS, but I'm not sure if that is possible and if it is, I would like to know how to read the data from the text file to get all the addresses.

So I'd like to know if there is any other way that the list of eligible addresses can be stored and retrieved easily in the smart contract(using IPFS).

I have never worked with IPFS so any help or tips would be appreciated!

I will use solidity to make the smart contract, and python with brownie to deploy and use it.

5
  • Contracts have no access to the outside world, someone or something should input the data and the question is who and how :) check this blog.chain.link/fetch-ipfs-api-data-token-distribution
    – Majd TL
    Feb 8, 2022 at 17:31
  • @MajdTL Oh alright. Would it be feasible to first upload the data into ipfs with python, then retrieve it within python and then pass this list to the contract while calling it's function? With this the file should be visible to everyone in the node.
    – binoy john
    Feb 8, 2022 at 18:02
  • you want to check if an address can vote or not? if yes then you dont need to store the addresses in a smart contract. you can build a merkle tree and then store only the root in the smart contract. and everyone who want to vote should proof that he is part of that merkle root
    – Majd TL
    Feb 9, 2022 at 12:41
  • air drops contracts do the same maybe you need to look for some examples. they cant store 100k addresses on chain. therefore they only store the merkle root and provide the proofs for public so people who can get the air drops can copy their proof and claim the token. here is an example github.com/Anish-Agnihotri/merkle-airdrop-starter
    – Majd TL
    Feb 9, 2022 at 12:44
  • @MajdTL I just read about merkle trees, and it sounds like a good idea! Thanks for letting me know about this :) You can post this as an answer because it looks correct!
    – binoy john
    Feb 9, 2022 at 16:54

1 Answer 1

0

If the purpose is only to check that an address can vote or not, then there is no need to store the addresses in a smart contract or import them. You can do that with a simple merkle tree and then store only the root in the smart contract. The voters will proof onChain that they are part of that merkle tree to be able to vote.

The general steps are:

  • get list of addresses
  • create the merkle root and proofs (off chain)
  • implement your voting smart contract and you need an extra method or contract for proof validation (e.g. https://docs.openzeppelin.com/contracts/4.x/api/utils#MerkleProof)
  • store the merkle root in the smart contract
  • store the proofs in a public reachable place for voters
  • when someone want to vote then he should send a transaction with his vote + the proofs that he is part of the merkle tree. if the proof is valid and the address of the sender is part of the tree then mark that address as voted in an extra mapping (so it will not vote again, and you need to check that every time) and then count the vote. otherwise the tx will revert

Air drops contracts do the same because they can't store 100k addresses on chain. Therefore, they only store the merkle root and provide the proofs on their websites or ipfs for the claimers. here is an example github.com/Anish-Agnihotri/merkle-airdrop-starter

some other examples:

https://thecibrax.com/using-merkle-trees-for-bulk-transfers-in-ethereum

https://medium.com/hackernoon/evolution-of-airdrop-from-common-spam-to-the-merkle-tree-30caa2344170

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.