Share:
Notifications
Clear all

Earn While Learning Web3 Programming>> Start Here FREE!!!

PROJECT: BUILD A CRYPTO HODLER BANK SMART CONTRACT

8 Posts
3 Users
4 Reactions
510 Views
2
Topic starter

PROJECT: BUILD A CRYPTO HODLER BANK SMART CONTRACT:

In Crypto people are usually too emotional and sell their crypto when market is crashing due to FUD.

Lets help them - How?

Create a Hodler Bank Fort Smart Contract that hold their funds for a set time and
they can't withdraw to sell even if market is going down to zero (which it would not anyway)
but their fears and greed makes it feel so.

i. Create A smart contract which allows user to Deposit Fund (Ether)

ii. It Hodl the deposited funds for 180 Days (about 6 Months)
NOTE: To test the SC, use 15 Minutes Hold time and when you confirm it works increase to 180 Days.

iii. User that attempt to withdraw before the 180 Days will get revert error message:
"You Are Impatient - Learn To Hodl For Better Profit - Come Back When Your Fund Is 180 Days Old - Mark Your Calendar!"

iv. User can withdraw back their deposited fund anytime after 180 Days of the SC Hodling it for them

v. Only User wallet that deposited will be allowed to withdraw amount deposited,
attempt by non depositor to withdraw fund from the SC will throw revert error.
Also, attempt by depositor (user) to withdraw more than deposited also throws revert error.

iv. Post your code in this forum
(NOTE: please, don't go and copy paste from other students in the forum, try things on your own, so you can master it yourself)

OPTIONAL -
Do and Send Video Testimonial of How The project works (test it in the short video) and How This Course Helped achieved it With Your Recommendation of dprogramminguniversity.com Earn while learning Web3 Programming with Free Courses and Support community forum and Certification For Publishing On Our Youtube Channel/Forum

 

POST YOUR PROJECT CODE IN THIS FORUM:

(NOTE: please, don't go and copy paste from other students in the forum, try things on your own, so you can master it yourself)

 

 

 

NOTE:

This Is A Project For Students From Our FREE Smart Contract Development With Solidity For Beginners Course (If you have not enrolled yet, you can join the course totally for FREE).

 

User Avatar Joshua Isaac 20/01/2022 10:50 pm

I'm having challenge to withdraw.

Any time I tried to withdraw it goes successful but no withdrawal was made

Solomon Foskaay Solomon Foskaay Topic starter 21/01/2022 7:48 am

@joshua can I have your smart contract code for check to help?

User Avatar Joshua Isaac 24/01/2022 12:28 pm

@foskaay why not sir

 

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;

contract bank {
    mapping ( address => uint ) balance;
    mapping ( address => uint ) depositeTimestamps;

//Deposite
function deposite (uint _newAmount) public {
    balance [msg.sender] += _newAmount;
    depositeTimestamps[msg.sender] = block.timestamp;
   
}
//Check Ballance
function checkBalance() public view returns(uint){
    return balance [msg.sender];
}

function withdraw(uint _amount) public payable returns (string memory){
    uint time = block.timestamp - depositeTimestamps[msg.sender];
    uint balanc = balance [msg.sender];
    if (time < 30){
        return "Holding time is yet to elasp!";
    }
    else if( balanc >= _amount){
     address payable withdrawTo = payable(msg.sender);
     withdrawTo.transfer(_amount);
     balance[msg.sender] = balanc - _amount;
     //return balance[msg.sender];
       
    }
}

}  
2 Answers
1

Sir please is it good for some one to copy code online?.

  Because I am trying to do my project, I Know what functions I need to make the contract work . But each time I look at the code in you training video I close my eyes and try to rewrite it I always miss out.

Though when I look at your code I don't try to cram it and I don't try to write it direct from you code .

  So I thought by now I should have known off hand.

    Dough if I see any function like payable or deposit in any code if it is not correct I will know but I can't write it if I should close my eyes.

   Please I need your advice.

Solomon Foskaay Solomon Foskaay Topic starter 01/12/2021 9:19 am

@leouloko I understand your point and personally I will discourage you from cramming codes (its a bad attitude that will limit your growth as a programmer). There are too many things to learn in programming that you can't afford to cram them all.

 

There are documentations and free programming courses and resources like this platform that you can always consult when you forget anything anytime online.

 

For example, you can always comeback to re-watch any lesson in our courses for free when you are doing a project that requires it but you forgot the code or it application and setup.

Instead, understand the concept and feel free to research and use other peoples codes online as long as it is not privately licensed nor break any copyright terms of the owner of the code.

 

Meanwhile, also be care of just copy-pasting codes online because some may have backdoors to hack your smart contract later.

.

So, always use and copy codes from trusted open source smart contract libraries like Openzeppelin (advance Solidity programming course will include openzeppelin so watch for it. Though I want more students in for the 101 first before moving to advance).

.

When copying codes from individuals, you should read the code carefully and understand every aspect of it to ensure no backdoor or things that can break your own smart contract before you use them. 

1
// SPDX-License-Identifier: MI
pragmasolidity>=0.7.0<0.9.0;

contract bank{

uint totalContractBalance =0;

function getContractBalance()publicreturns(uint){
return totalContractBalance;

mapping(address => uint) balance;

function addBalance(address userAddress,uint)publicpayable{
            balance[userAddress]= amount;
            totalContractBalance = totalContractBalance + amount;
}
}

}
 
 
// please sir i have been having problem runing this code, i have been stock here for more than a week now//.
Solomon Foskaay Solomon Foskaay Topic starter 08/12/2021 10:01 am

@leouloko well done and keep pushing and you will get better but there are some things you need to master as a beginner now and not when you become a pro.

If you fail to master now, you might end up writing bad and hard to read code which will be hard also to maintain by you or other devs in the future.

 

(1) COMMENT

I remembered in one of the lesson exercises, I specifically told you to always have your code well commented.

I bet it with you, the code you wrote above, even if it works fine today and then you move on with other projects and come back to it after 1 year after, you will find it so hard to understand what it does easily and will have to spend hours reading it line by line to recollect even though you coded it yourself.

WHY?

Because it is not commented nor well spaced.

The comments may make your coding speed slower but better than speedy coding that produces buggy codes.

 

.

.

 

'

(2) SCOPE - State Vs Local Variables

In one of the course lessons, I discussed about State Variable (Global Scope) vs Local Variable (Local Scope). You need to rewatch that lessons over again.

WHY?

Because your code shows you don't understand it and it is essential to write a bug-free code smart contract.

For example, Mapping should be a State/Global Variable so that any function that comes below it can access it 

BUT

You put it inside a function which made it became a Local Variable and losses is essential State/Global Scope access needed to maintain the mapping usage.

It also means other functions outside that function can not access the mapping.

Kindly take time to rewatch these lessons over again - PLEASE!

 

'

.

 

(3) THE CODE

There are more corrections but this is getting long already, so what I did was to copy-paste your code above into REMIX IDE and reformatted it below:

 

Don't Copy-paste it so you can learn to discover and resolve your mistakes when coding,

Instead, open remix with your original code and compare them to see where you got things wrong and then fix them one by one till your code errors disappear and compile and deploys successfully.

I will be available to give further supports if need be but take time to try with the solution below first:

.

.

-

 

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0<0.9.0;

 

contract Bank {

 

//balance mapping
mapping(address => uint) balance;
//track total Smart contract balance
uint totalContractBalance = 0;
 
 
//get contract total balance
function getContractBalance() public view returns(uint){
    return totalContractBalance;
}
 
 
//add/deposit fund into contract
function addBalance(uint amount) public payable{
            //add deposited amount to the balance mapping of the depositor msg.sender
            balance[msg.sender] += amount;

 

            //totalContractBalance += amount; alternative shortest way to write the code below
            totalContractBalance = totalContractBalance + amount;
}

 

}

 

-

.

.

Share: