Loading...
In the today's world which is of full technology we mainly come across the online payment many time we use the refer code from our friend and earn the reward of the money from it your friend also get some earning if you use the refer code from the user .but if you think how this should be done if you have the programming language called as a solidity how this particular concept should be done within it.let me show you how can we do this with the help of solidity.for that we need two type of the mapping one is to store the user address is valid or not and another is for the user balance also
mapping(address => bool)public user;
mapping(address=>uint256)public balance;
After this we need the function called as the create the account of the user in this we assign one require statement through which we determine that the given user is not already created the account in this contact then if it is the new user then we assign it new and return the value as a true after the successfully complitation of the function.
function createaccount() public returns(bool)
{
require(user[msg.sender]==false,'User is existed');
user[msg.sender]==true;
return true;
}
after successfully create the user account the another user who want to create it's account now he refer the account of the previous account created user and after this both of you and that user get the 1 ether in it's account after the successfully execution of the function.
function refral(address referal) public payable
{
require(user[referal]==true,"user not existed");
require(user[msg.sender]==true,"not existed");
balance[referal]=balance[referal]+1*10**18;
balance[msg.sender]=balance[msg.sender]+1*10**18;
}
in which we have created the two require condition through which we can verify that the user is valid or not and also create the account of other user in the contract.
function checkbalance(address _add) public view returns(uint256)
{
return balance[_add];
}
All the above successfully after this we want to check that the successfully above function is executed or not for this we created the function to check the balance of the each account involve within that contract