Skip to content

Instantly share code, notes, and snippets.

View Davidegloh's full-sized avatar

Davidegloh Davidegloh

View GitHub Profile
@Davidegloh
Davidegloh / oop.sol
Last active September 6, 2021 14:08
[OOP - Inheritance - Solidity] #inheritance #oop
/*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.
@Davidegloh
Davidegloh / event.sol
Last active September 1, 2021 13:54
[Event - Solidity]#event
//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 {
@Davidegloh
Davidegloh / modifier.sol
Created August 31, 2021 15:49
[modifier - Solidity] #modifier
//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) {
@Davidegloh
Davidegloh / assert.sol
Created August 31, 2021 15:45
[Assert - Solidity] #assert
//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)
@Davidegloh
Davidegloh / require.sol
Last active August 31, 2021 15:37
[Require - Error Handling -Solidity]
//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() {
@Davidegloh
Davidegloh / gas.sol
Created August 31, 2021 15:34
[Gas - Solidity] #gas
//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
@Davidegloh
Davidegloh / Visibility.sol
Last active August 31, 2021 15:32
[Visibility -Solidity] #visibility
//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)
@Davidegloh
Davidegloh / mapping.sol
Last active August 31, 2021 15:32
[Mapping -Solidity] #mapping
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 :
@Davidegloh
Davidegloh / arrays.sol
Last active August 31, 2021 15:32
[Arrays-Solidity] #arrays
pragma solidity 0.7.5;
contract HelloWorld {
int [] numbers;//we initialize it empty
function addNumber(int _number) public {
numbers.push(_number);
}
@Davidegloh
Davidegloh / setterFunction.sol
Created August 18, 2021 14:31
[Setter Function - Solidity] #setterfunction
pragma solidity 0.7.5;
contract HelloWorld {
int number;
function getNumber() public view returns(int){
return number;
}