Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Fahmi Ahmad khofesh

🏠
Working from home
View GitHub Profile
@khofesh
khofesh / contracts...ABIExample.sol
Created Sep 21, 2021
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=
View contracts...ABIExample.sol
pragma solidity ^0.8.4;
contract AbiExample {
string public myString = "hello world!";
}
@khofesh
khofesh / contracts...EventExample.sol
Created Sep 14, 2021
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=
View contracts...EventExample.sol
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 Sep 12, 2021
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=
View contracts...Owned.sol
pragma solidity ^0.8.4;
contract Owned {
address owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
@khofesh
khofesh / contracts...InheritanceModifier.sol
Created Sep 12, 2021
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=
View contracts...InheritanceModifier.sol
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 Sep 12, 2021
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=
View contracts...FunctionsExample.sol
//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 Sep 8, 2021
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=
View contracts...AlwaysFails.sol
//SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
contract AlwaysFails {
function aFunction() public {
require(false, "Error message");
}
}
@khofesh
khofesh / contracts...Exceptions.sol
Created Sep 8, 2021
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=
View contracts...Exceptions.sol
//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 Sep 8, 2021
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=
View contracts...mappingStructs.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
contract MappingsStructExample {
struct Payment {
uint amount;
uint timestamp;
}
@khofesh
khofesh / contracts...SimpleMappingExample.sol
Created Sep 8, 2021
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=
View contracts...SimpleMappingExample.sol
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 Sep 8, 2021
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=
View contracts...StartingStopping.sol
pragma solidity ^0.8.4;
contract StartingStopping {
address public owner;
bool public paused;
constructor() {
owner = msg.sender;
}