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
/*Inheritance is one of the pillars of object orientation and Solidity supports inheritance between smart contracts. Inheritance is the process of defining multiple contracts that are related to each other through parent-child relationships. | |
contract that is inherited = parent contract | |
contract that inherits = child contract | |
Inheritance is mostly about code-reusability. There is a is-a relationship between base and derived contracts and all public and internal scoped functions and state variables are available to derived contracts. | |
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
//Event | |
// Event : C'est une façon de log des events et de la data durant l'execution d'une fonction. Comme un console.log en JS. Lorsque la fonction est executée allez dans la console et regarder dans logs. Les arguments des logs seront affichés. Les events sont importants pour que les frontends in dapps can react to changes in our contracts. | |
//Exemple : pour la function addBalance : | |
//event balanceAdded(uint amount, address depositedTo); // Event : C'est une façon de log des events et de la data during a function execution. En arguments s'affichera // le montant déposé et l'addresse recevant les fonds. | |
pragma solidity 0.7.5; | |
contract Bank { | |
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) { |
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
//assert - solidity | |
//ligne 36 depuis remix | |
pragma solidity 0.7.5; | |
contract Bank { | |
mapping (address => uint) balance; //ligne de code à tapper pour le mapping. Mapping def. à partir d'une key on obtient une value. (K -> V) |
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
//Error Handling Require - Solidity code | |
pragma solidity 0.7.5; | |
contract Bank { | |
mapping (address => uint) balance; //ligne de code à tapper pour le mapping. Mapping def. à partir d'une key on obtient une value. (K -> V) | |
address owner; // on "set" a state variable qui est une adresse que l'on appelle owner | |
constructor() { |
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
//Gas - Solidity | |
//Gas powers the EVM.This is a reward for the miners executing smart contract transactions. It is a cost of execution. It is payed by the sender. | |
//IMPORTANT : Gas consumption by operation is fixed | |
// Price of one Gas unit is not fixed |
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
//Visibility | |
// it is a way to restrict access to functions and state variables inside our smart contract | |
//- Public (everyone can accessed the functions and call it but can't edit it) | |
//- Private (can only be accessed from the contract within and the functions can only be executed from the contract itself) | |
//- Internal (can only be accessed from within the contract itself and from contracts deriving from it / which inherited from it. | |
// - External ( can only be executed from other contracts and services like remix for instance) |
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
Mapping Solidity : | |
//Mapping is a key-value storage. They are also called dictionnary. | |
// K -> V | |
// address -> Balance | |
// so how do we defined a mapping ? | |
//mapping (keyType => valueType) name; | |
// Exemple : mapping(address => uint) balance; | |
// Then, when we want to add a value to a mapping/a spefiic key we assign this value like this : |
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
pragma solidity 0.7.5; | |
contract HelloWorld { | |
int [] numbers;//we initialize it empty | |
function addNumber(int _number) public { | |
numbers.push(_number); | |
} |
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
pragma solidity 0.7.5; | |
contract HelloWorld { | |
int number; | |
function getNumber() public view returns(int){ | |
return number; | |
} | |
NewerOlder