Skip to content

Instantly share code, notes, and snippets.

@kenjirai
kenjirai / Call.sol
Created March 8, 2019 03:50
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.5.0+commit.1d4f565a.js&optimize=false&gist=
pragma solidity ^0.4.23;
contract D {
uint public n;
address public sender;
function callSetN(address _e, uint _n) {
_e.call(bytes4(sha3("setN(uint256)")), _n); // E's storage is set, D is not modified
}
@kenjirai
kenjirai / BeforeCheck.sol
Created January 30, 2019 03:46
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.5.1+commit.c8a2cb62.js&optimize=false&gist=
pragma solidity ^0.5.0;
import "./IndirectEventEmitter.sol";
contract EventEmitter {
event Argumentless();
event ShortUint(uint8 value);
event ShortInt(int8 value);
event LongUint(uint256 value);
event LongInt(int256 value);
@kenjirai
kenjirai / CheckStruct.sol
Created January 4, 2019 11:33
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.5.2+commit.1df8f40c.js&optimize=false&gist=
pragma solidity >=0.4.22 <0.6.0;
/// @title Voting with delegation.
contract Ballot {
// This declares a new complex type which will
// be used for variables later.
// It will represent a single voter.
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted
@kenjirai
kenjirai / CheckStruct.sol
Created January 4, 2019 05:54
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.5.2+commit.1df8f40c.js&optimize=false&gist=
pragma solidity >=0.4.22 <0.6.0;
/// @title Voting with delegation.
contract Ballot {
// This declares a new complex type which will
// be used for variables later.
// It will represent a single voter.
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted
@kenjirai
kenjirai / CheckStruct.sol
Created January 3, 2019 11:44
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.5.2+commit.1df8f40c.js&optimize=false&gist=
pragma solidity >=0.4.22 <0.6.0;
/// @title Voting with delegation.
contract Ballot {
// This declares a new complex type which will
// be used for variables later.
// It will represent a single voter.
struct Voter {
uint weight; // weight is accumulated by delegation
bool voted; // if true, that person already voted
@kenjirai
kenjirai / ArrayTesting.sol
Created January 2, 2019 11: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.4.18+commit.9cf6e910.js&optimize=false&gist=
pragma solidity ^0.5.0;
contract ArrayTesting {
uint[] public num;
function pushInt(uint value) public {
num.push(value);
}
function getLength() public view returns(uint) {
@kenjirai
kenjirai / SuperCheck.sol
Created November 14, 2018 10:21
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=true&gist=
pragma solidity ^0.4.24;
/*
Understanding Method overiding by mulitle child contracts
Parent contract is Crowdsale,
Child contracts are CappedCrowdSale and TimeCrowdsale. Both overides the Parent Contract method _preValidatePurchase.
Grand Child contract, SampleCrowdsale first chooses to inhert from it's parent TimeCrowdsale and later contract CappedCrowdSale.
Since the inherted method overiding happens in FIFO style, TimeCrowdsale method is called first and CappedCrowdSale later. Super must
be called by both child contract inorder the complete the method overiding chain.
@kenjirai
kenjirai / Check.sol
Created September 20, 2018 16:35
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.25+commit.59dbf8f1.js&optimize=true&gist=
pragma solidity ^0.4.23;
contract D {
uint public n;
address public sender;
function callSetN(address _e, uint _n) {
_e.call(bytes4(sha3("setN(uint256)")), _n); // E's storage is set, D is not modified
}
}
@kenjirai
kenjirai / CrowdFunding.sol
Created August 26, 2018 12:26
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&gist=
pragma solidity ^0.4.11;
contract CrowdFunding {
// Defines a new type with two fields.
struct Funder {
address addr;
uint amount;
}
struct Campaign {
@kenjirai
kenjirai / CrowdFunding.sol
Created August 26, 2018 11:37
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&gist=
pragma solidity ^0.4.11;
contract CrowdFunding {
// Defines a new type with two fields.
struct Funder {
address addr;
uint amount;
}
struct Campaign {