Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Shoup shoupn

View GitHub Profile
@shoupn
shoupn / contracts...Fundraiser.sol
Created Feb 21, 2022
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.4.26+commit.4563c3fc.js&optimize=false&runs=200&gist=
View contracts...Fundraiser.sol
pragma solidity ^0.4.24;
contract Fundraiser {
mapping(address=>uint) balances;
// VULNERABLE
function withdrawCoins(){
uint withdrawAmount = balances[msg.sender];
Wallet wallet = Wallet(msg.sender);
wallet.payout.value(withdrawAmount)();
@shoupn
shoupn / contracts...LemonadeStand.sol
Created Feb 18, 2022
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.11+commit.d7f03943.js&optimize=false&runs=200&gist=
View contracts...LemonadeStand.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
contract LemonadeStand {
address owner;
uint skuCount;
enum State { ForSale , Sold, Shipped }
@shoupn
shoupn / contracts...Token.sol
Created Feb 5, 2022
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.11+commit.d7f03943.js&optimize=false&runs=200&gist=
View contracts...Token.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract myToken {
string public constant name = "Tokenomics";
string public constant symbol = "TOK";
uint8 public constant decimals = 18; // 18 is the most common number of decimal places
uint _totalSupply;
@shoupn
shoupn / contracts...EventsContract.sol
Last active Feb 5, 2022
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...EventsContract.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract EventsContract {
// Represents the time when the bidding will end
uint biddingEnds = block.timestamp + 5 days;
struct HighestBidder {
address bidder;
string bidderName;
@shoupn
shoupn / contracts...Inheritance.sol
Created Feb 5, 2022
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...Inheritance.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract MainContract {
uint public value;
constructor (uint amount) {
value = amount;
}
@shoupn
shoupn / contracts...Modifiers2.sol
Created Feb 4, 2022
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...Modifiers2.sol
pragma solidity >=0.7.0 <0.9.0;
contract Modifiers2 {
uint public minimumOffer = 100;
modifier minimumAmount(){
//Could also use require( msg.value >= minimumOffer)
if(msg.value >= minimumOffer){
_;
@shoupn
shoupn / contracts...Functions.sol
Last active Feb 4, 2022
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.11+commit.d7f03943.js&optimize=false&runs=200&gist=
View contracts...Functions.sol
pragma solidity >=0.8.10;
contract FunctionsContract {
string ownerName;
uint8 ownerAge;
// Constructor
constructor (string memory name, uint8 age) public {
ownerName = name;
View ethereumSolidityDataTypesNotes.md

Solidity Notes

Solidity has basic structure like so

Contracts

contract NewContract {
  uint data; // contract fields like this are in storage
  
constructor(uint _data) public {
@shoupn
shoupn / contracts...GlobalVariables.sol
Created Feb 4, 2022
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.4.24+commit.e67f0147.js&optimize=false&runs=200&gist=
View contracts...GlobalVariables.sol
pragma solidity >=0.4.24;
contract GlobalVariables {
string public lastCaller = "not-set";
// Demonstrates the use of the ether subdenominations
function etherUnitsTest() public pure returns(bool) {
// True
bool value = (1 ether == 1000 finney);
@shoupn
shoupn / contracts...StringConversion.sol
Created Feb 4, 2022
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...StringConversion.sol
pragma solidity >=0.4.22 <0.9.0;
contract StringConversion {
function getStringElementAtIndex(uint index, string memory myString) public pure returns (byte){
bytes memory stringToBytes = bytes(myString);
return stringToBytes[index];
}
}