BlockChain Based Survey Application with Flutter

Hello, are you ready to step into the world of blockchain? Although most of us are familiar blockchain with today’s trends, digital currencies (BTC, ETH), blockchain is not just about money. Blockchain technology is a virgin continent waiting to be discovered. Today, we will set foot on this continent with the help of Flutter and Ethereum Smart Contracts.

Today, we will talk about how to use an blockchain based survey application using Flutter and Ethereum Smart Contracts. But first, the question we need to ask is, what does it mean for an application to be blockchain-based? What is Blockchain? Is it something I can eat? What capabilities does it provide to our applications?

Let’s talk about blockchain. We can say about blockchain that is a large ledger that protects transactions and assets and ensures that they cannot be changed.

Blockchain technology can provide transparency, reliability or privacy on our applications in the direction we aim for.

In the survey application that we will develop, our aim will be to protect the data received from the participant, as well as the confidentiality of participant’s information and the transparency of the survey results as image below.

When the project is finished, we will have an application like the one below.

First of all we should develop our smart contract after planning the project and there is a popular web application(ide) to writing, compiling and deploying. This application is Remix — Ethereum IDE.

I can hear you saying stop talking and show me the code so let’s start coding.

In our application we need some spesific function. There are :

We have 4 base function.

  • createQuestion() : This function has two parameters as _content and answer. _content is the question and also we take answers using string list easliy. This function creates the question and keeps them in the blockchain network.
  • createSurvey() : This function is used to create a survey on the smart contract. It needs the id of the questions that have already been created and wanted to be added to the survey, and a name for the survey.
  • createParticiant(): This function is used to create participants for the survey on the smart contract. Participants can be easily created with name and age information.
  • joinTheSurvey(): It is the function that allows the participant to participate in the survey. It needs the id of the survey the participant wants to participate in and the answers given to the questions. It should work as soon as the survey is submitted.

Our smart contract is ready now. How can we integrate with Flutter ? At this point we’re starting to do some cool stuff and we should use some blockchain tools.

  • Metamask : To deploy smart contract on Web3(Injected Web3 on Remix)
  • Infura or Ganache (I used Infura)

After deploying the Ethereum smart contract as Injected Web3, let’s open a free ethereum project on Infura. We will use this as Ethereum Client.

Let’s start Flutter side. On the Flutter side, we have a json file that we need to add to the project first. We can get the information contained in this json file on the compile screen or deploy screen on the Remix ide. You will see a small text ABI under the compiler window. If you click on it, some data will be copied to the clipboard. Just paste it into a .json file.

Let’s talk a little bit about the service. In the service side we should create base functions in smart contract as below;

You can show your Flutter skills in the section after you write the services.

Full code

Thanks For Reading, Follow Me For More Blockchain and Flutter Contents

Senior Year Computer Engineering Student