Need help making a dapp

hiteshh

New member
member
I wish to make an application that reinforces habits among users and/or helps them drop bad ones, by letting them stake some ether onto my application, which is returned to them if and only if they complete certain tasks. If they fail at their tasks, their ether should flow into my account. There are ample resources online that guide one on how to make a dapp, but not much when it comes to building a mobile dapp. So, for now, I will just stick to web applications. Heres what i gathered so far;

1.First, I need to develop a smart contract on remix

2.Deploy the smart contract on a test network using meta mask

3.Install Web3.js library, that comes with node.js

4.Make a simple front end, a single html file

5.Connect the front end to the smart contract

6.Get to trigger the required method on the press of a button

Heres my smart contract so far: The task included in this contract involves quitting instagram for 5 days.

Code:
pragma solidity ^0.8.6;
contract Snowball {
mapping(address => uint) public balances;
address public me;
uint startTime;

function Snowball public {
   me = msg.sender;
}

// user claims staked ethers, which are returned to him if he successfully completed the task
function claim() public {
   if (block.timestamp > start + 5 days && !checkFailure()) {
       balances[address(this)] -= amount;
       balances[msg.sender] += amount;
    }
}

function checkFailure() public returns(bool) {
   // if (user cant quit instagram for 5 days) {
       // return true;
       //}
       //return false;
}

// user depositing some ether into the smart contract's account
function stake() public {
   // i am yet to add modifiers
   balances[msg.sender] -= amount;
   balances[address(this)] += amount;
   startTime = block.timestamp;
}

// I claim the staked ethers if the user doesnt do so after 10 days
function withdraw() public {
   if (block.timestamp > start + 10 days && checkFailure()) {
   me.transfer(address(this).balance);
   }
} }

Heres what i am yet to figure out;

1.How to fetch data from a users phone (is that even possible?). For instance, if i want to know how much time a user has spent on instagram, or the distance he has run by accessing data on his Strava, how do i do that?

  1. The smart contract above looks like it is merely keeping track of the ethers, but not actually moving ethers around. As in, i doubt it is reflected in the users accounts. How do i change this?
  2. I once came across a dapp that showed a different user interface to the owner of the dapp. I am not sure how to do that; different user interfaces for different accounts. In this case, it wouldnt make any sense for the withdraw button to be visible to anyone but me.
Please help me out here. Also, did i miss anything? Will i face any issues with the above approach? Any guidance, criticism, advice is appreciated!
 

Nomad

New member
member
I have not tried my hands on building smart contracts or decentralized applications but I really want to learn how to build blockchain-based projects. I would also like to learn to build cryptocurrency and crypto-token someday. By the way, do you know how do I get started on building dapp on ethereum?
 

hiteshh

New member
member
I have not tried my hands on building smart contracts or decentralized applications but I really want to learn how to build blockchain-based projects. I would also like to learn to build cryptocurrency and crypto-token someday. By the way, do you know how do I get started on building dapp on ethereum?
There are plenty of channels on youtube for the same. And theres this blockchain specialisation course on coursera, which i think is a good place to start...i found it to be quite comprehensive...and if you get stuck somewhere (like i seem to have right now), you can just consult forums intended to help out developers...and theres stack overflow ofc....u can also try reaching out to ppl who you think can help...like youtubers...or bloggers....through their email...now i dont know how well this works...i m just telling you what i am doin...
 

Help keep us alive!

  1. Campaign goal
    $15.00 of $100.00
Top Bottom