Skip to content

Instantly share code, notes, and snippets.

View khofesh's full-sized avatar
🏠
Working from home

Fahmi Ahmad khofesh

🏠
Working from home
View GitHub Profile
@khofesh
khofesh / contracts...ABIExample.sol
Created September 21, 2021 14:16
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.0+commit.26b70077.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.4;
contract AbiExample {
string public myString = "hello world!";
}
@khofesh
khofesh / contracts...EventExample.sol
Created September 14, 2021 15:49
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.4;
contract EventExample {
mapping(address => uint) public tokenBalance;
event TokensSent(address _from, address _to, uint _amount);
constructor() {
tokenBalance[msg.sender] = 100;
}
@khofesh
khofesh / contracts...Owned.sol
Created September 12, 2021 15:53
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.4;
contract Owned {
address owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
@khofesh
khofesh / contracts...InheritanceModifier.sol
Created September 12, 2021 15:53
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.4;
import "./Owned.sol";
contract InheritanceModifier is Owned {
mapping(address => uint) public tokenBalance;
uint tokenPrice = 1 ether;
@khofesh
khofesh / contracts...FunctionsExample.sol
Created September 12, 2021 13:39
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.3+commit.8d00100c.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract FunctionsExample {
mapping(address => uint) public balanceReceived;
address payable owner;
constructor() {
@khofesh
khofesh / contracts...AlwaysFails.sol
Created September 8, 2021 15:07
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.6+commit.7338295f.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
contract AlwaysFails {
function aFunction() public {
require(false, "Error message");
}
}
@khofesh
khofesh / contracts...Exceptions.sol
Created September 8, 2021 15:07
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.6+commit.7338295f.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
contract Exceptions {
mapping(address => uint64) public balanceReceived;
function receiveMoney() public payable {
assert(msg.value == uint64(msg.value));
balanceReceived[msg.sender] += uint64(msg.value);
@khofesh
khofesh / contracts...mappingStructs.sol
Created September 8, 2021 15:07
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.6+commit.7338295f.js&optimize=false&runs=200&gist=
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
contract MappingsStructExample {
struct Payment {
uint amount;
uint timestamp;
}
@khofesh
khofesh / contracts...SimpleMappingExample.sol
Created September 8, 2021 15:07
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.6+commit.7338295f.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.4;
contract SimpleMappingExample {
mapping(uint => bool) public myMapping;
mapping(address => bool) public myAddressMapping;
mapping (uint => mapping(uint => bool)) uintUintBoolMapping;
function setValue(uint _index) public {
myMapping[_index] = true;
}
@khofesh
khofesh / contracts...StartingStopping.sol
Created September 8, 2021 15:07
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.6+commit.7338295f.js&optimize=false&runs=200&gist=
pragma solidity ^0.8.4;
contract StartingStopping {
address public owner;
bool public paused;
constructor() {
owner = msg.sender;
}