Skip to content

Instantly share code, notes, and snippets.

View wissalHaji's full-sized avatar

Wissal Haji wissalHaji

View GitHub Profile
@wissalHaji
wissalHaji / HelloWorld.sol
Last active October 26, 2020 19:56
State and local variables in solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
contract HelloWorldContract {
address owner; // state variable
function helloWorld() external pure returns(string memory){
@wissalHaji
wissalHaji / address.sol
Last active October 27, 2020 09:08
address payable to address conversion
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
contract HelloWorldContract {
function transferFund(address payable receiver, uint amount) payable external {
address newAddress = receiver;
receiver.transfer(amount); // OK
@wissalHaji
wissalHaji / HelloWorldContract.sol
Last active October 27, 2020 11:39
Example for the msg.sender property
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
contract HelloWorldContract {
string greeting;
address owner;
constructor() {
@wissalHaji
wissalHaji / checker.sol
Created October 27, 2020 12:17
Balance and address checker
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
contract Checker {
address owner;
constructor() {
owner = msg.sender;
}
@wissalHaji
wissalHaji / DataStorage.sol
Last active November 3, 2020 12:12
test for data location assignments
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.7.0;
contract DataLocationTest {
uint[] stateVar = [1,4,5];
function foo() public{
// case 1 : from storage to memory
@wissalHaji
wissalHaji / StorageArrays.sol
Last active November 14, 2020 13:21
Example of storage arrays
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract A {
uint256[] public numbers;// dynamic length array
address[10] private users; // fixed length array
uint8 users_count;
function addUser(address _user) external {
@wissalHaji
wissalHaji / MemoryArray.sol
Created November 14, 2020 14:45
Memory array in solidity example
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract B {
function createMemArrays() external view {
uint256[20] memory numbers;
numbers[0] = 1;
numbers[1] = 2;
@wissalHaji
wissalHaji / Crud.sol
Created November 15, 2020 19:05
simple crud with solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract Crud {
struct User {
uint256 id;
string name;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;
pragma experimental ABIEncoderV2;
contract Wallet {
address[] public approvers;
uint8 public quorum;
struct Transfer {
@wissalHaji
wissalHaji / Token.sol
Last active December 6, 2020 12:11
Gist for the new post in medium : Interacting with other contracts from within a contract
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.8.0;
contract OwnedToken {
TokenCreator creator;
address owner;
bytes32 public name;
constructor(bytes32 _name) {
owner = msg.sender;