Created
August 31, 2021 15:49
-
-
Save Davidegloh/8c42e5d4fff3259d057b7d210549f4c8 to your computer and use it in GitHub Desktop.
[modifier - Solidity] #modifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Modifiers - Solidity | |
// Modifiers are a tiny fonction to seperate logic and re-use logic on multiple places in a contract. We run it before we run the function code . | |
Ex : modifier onlyOwner { | |
require (owner == msg.sender); | |
} | |
_; | |
modifier cost (uint price) { | |
require (msg.value >= price); | |
} | |
_; | |
function addBalance(uint _toAdd) public onlyOwner returns(uint) { //fonction addBalance pour rajouter un uint à une address | |
balance[msg.sender] += _toAdd; // ou aussi balance [msg.sender] + _toAdd. Ici on rajouter une valeur à l'adresse de l'envoyeur | |
return balance[msg.sender]; //ici on retourne la balance de l'envoyeur "[msg.sender]"" updaté | |
} | |
function getBalance() public view returns(uint) cost(10) {// fonction pour afficher une balance qui retourne un integer de l'adresse de l'envoyeur. | |
return balance[msg.sender]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment