Survey Participant Contract

Welcome to this short tutorial where we'll explore how to design and deploy a smart contract using Marlowe. In this guide, we'll create a simple survey contract that records a participant response on the blockchain and rewards them with an NFT.


Survey

The survey will consist of 5 questions. The first 4 are statements that you need to agree or disagree and the 5th question is a text-based answer.

The questions are:

  1. I’d like to use/recommend Marlowe for future dApps
    • 1 - Strongly disagree
    • 2 - Disagree
    • 3 - Neutral
    • 4 - Agree
    • 5 - Highly agree
  2. The survey contract was easy to design
    • 1 - Strongly disagree
    • 2 - Disagree
    • 3 - Neutral
    • 4 - Agree
    • 5 - Highly agree
  3. This tutorial is helpful
    • 1 - Strongly disagree
    • 2 - Disagree
    • 3 - Neutral
    • 4 - Agree
    • 5 - Highly agree
  4. I am an experienced web3 developer
    • 1 - Strongly disagree
    • 2 - Disagree
    • 3 - Neutral
    • 4 - Agree
    • 5 - Highly agree
  5. Please share any comments (240 char max)

Step 1: Design the contract

To design the contract we'll use the Blockly editor in the Marlowe Playground. The questions will be modeled using Choice Action. Each question will be answered by the Address $SURVEY_PARTICIPANT_ADDR participant before a parameterized answer timeout. If the contract timeouts we close it.

Create the 5 questions blocks with the following parameters:

Choice Name Bounds
answer1 [1 - 5]
answer2 [1 - 5]
answer3 [1 - 5]
answer4 [1 - 5]
answer5 [1 - 1099511627775]

Each question block should resemble the following example:

Survey question block

After the questions, the $CUSTODIAN_ADDRparticipant will deposit 1 Token "6fcbab5bb175b420cd060edb63af74c5b3d4687163f282ddc5377dd3" "SurveyReward" directly into the survey participant account before a parameterized reward timeout and then close the contract. After the contract is closed, the payment of the reward token will be made automatically.

Survey reward block

Step 2: Simulate and download the contract

After you have created the contract, send it to simulation and check that there is only one path to receive the SurveyReward, which is to answer the 5 questions and for the custodian to make the deposit.

Set the reward timeout bigger than the answer timeout way far in the future, download the contract as survey.json

Survey contract parameters

Step 3: Upload the contract

After you download the contract, you can upload it here:



Create contract log