Created
May 18, 2019 00:08
-
-
Save theowlsden/27419d4a6c68ba311b5619290adbd315 to your computer and use it in GitHub Desktop.
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.7+commit.6da8b019.js&optimize=false&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract childAllowance{ | |
address parentAddress; | |
address childAddress; | |
uint public allowance; | |
constructor(address _parent) public{ | |
parentAddress = _parent; | |
} | |
modifier onlyAddress(address person) { | |
require(msg.sender == person); | |
_; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
contract Hashit{ | |
string public password; | |
bytes32 public hashedpassword; | |
function hashItforMe(string memory _password) public{ | |
password = _password; | |
hashedpassword = sha256(bytes(_password)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.4.22 <0.6.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { | |
uint voteCount; | |
} | |
address chairperson; | |
mapping(address => Voter) voters; | |
Proposal[] proposals; | |
/// Create a new ballot with $(_numProposals) different proposals. | |
constructor(uint8 _numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
proposals.length = _numProposals; | |
} | |
/// Give $(toVoter) the right to vote on this ballot. | |
/// May only be called by $(chairperson). | |
function giveRightToVote(address toVoter) public { | |
if (msg.sender != chairperson || voters[toVoter].voted) return; | |
voters[toVoter].weight = 1; | |
} | |
/// Delegate your vote to the voter $(to). | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; // assigns reference | |
if (sender.voted) return; | |
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
to = voters[to].delegate; | |
if (to == msg.sender) return; | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegateTo = voters[to]; | |
if (delegateTo.voted) | |
proposals[delegateTo.vote].voteCount += sender.weight; | |
else | |
delegateTo.weight += sender.weight; | |
} | |
/// Give a single vote to proposal $(toProposal). | |
function vote(uint8 toProposal) public { | |
Voter storage sender = voters[msg.sender]; | |
if (sender.voted || toProposal >= proposals.length) return; | |
sender.voted = true; | |
sender.vote = toProposal; | |
proposals[toProposal].voteCount += sender.weight; | |
} | |
function winningProposal() public view returns (uint8 _winningProposal) { | |
uint256 winningVoteCount = 0; | |
for (uint8 prop = 0; prop < proposals.length; prop++) | |
if (proposals[prop].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[prop].voteCount; | |
_winningProposal = prop; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import "remix_tests.sol"; // this import is automatically injected by Remix. | |
import "./ballot.sol"; | |
contract test3 { | |
Ballot ballotToTest; | |
function beforeAll () public { | |
ballotToTest = new Ballot(2); | |
} | |
function checkWinningProposal () public { | |
ballotToTest.vote(1); | |
Assert.equal(ballotToTest.winningProposal(), uint(1), "1 should be the winning proposal"); | |
} | |
function checkWinninProposalWithReturnValue () public view returns (bool) { | |
return ballotToTest.winningProposal() == 1; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract Counter { | |
uint256 counterValue; | |
function increaseCount() public { | |
counterValue = counterValue + 1; | |
} | |
function reset() public { | |
counterValue = 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol"; | |
contract myCrowdsale is Crowdsale{ | |
constructor ( | |
uint256 rate, | |
address payable wallet, | |
ERC20 token | |
) public Crowdsale(rate, wallet, token) | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract beGone{ | |
uint256 counterValue; | |
function increaseCount() public { | |
counterValue = counterValue + 1; | |
} | |
function killa() public { | |
selfdestruct(msg.sender); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract beGone1{ | |
uint256 counterValue; | |
function increaseCount() public { | |
counterValue = counterValue + 1; | |
} | |
function killa() public { | |
selfdestruct(msg.sender); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol"; | |
contract heheToken is ERC20 { | |
string public name = "heheToken"; | |
string public symbol = 'HT'; | |
uint public decimals = 18; | |
uint public INITIAL_SUPPLY = 69 * (10 ** decimals); | |
constructor() public { | |
_mint(msg.sender, INITIAL_SUPPLY); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; | |
contract testCollectible is ERC721{ | |
string public name = "heheToken"; | |
string public symbol = 'HT'; | |
uint256 tokenId; | |
struct Color{ | |
uint8 red; | |
uint8 blue; | |
uint8 green; | |
} | |
Color[] colors; | |
constructor() public{ | |
} | |
function mint() public{ | |
Color memory _color = Color(uint8(now), uint8(now-69), uint8(now-1000)); | |
uint _id = colors.push(_color) -1; | |
_mint(msg.sender, _id); | |
} | |
function getColorfromId(uint id) public view returns(uint8, uint8, uint8){ | |
return (colors[id].red, colors[id].blue, colors[id].green); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import './destruct1.sol'; | |
contract Escrow is beGone1 { | |
address payable public payee; | |
address payable public beneficiary; | |
address public witness; | |
address public judge; | |
bool public testified; | |
bool public escalated; | |
modifier only(address role) { | |
require(msg.sender == role); | |
_; | |
} | |
constructor(address payable _payee, address payable _beneficiary, address _witness) public { | |
//TODO: set the payee to _payee, beneficiary to _beneficiary and witness to _witness | |
// msg.sender is the person who calls this function (in this case: creates the contract) | |
payee = _payee; | |
beneficiary = _beneficiary; | |
witness= _witness; | |
judge = msg.sender; | |
} | |
// TODO: fill in the function bodies of testify (1 line of code). Hint: look at the boolean testified (line 9) | |
function testify() public only(witness) { | |
testified = true ; | |
} | |
// TODO: fill in the function bodies of escalate (1 line of code) | |
function escalate() public only(payee) { | |
escalated = true; | |
} | |
// (this) returns the contract address | |
function judgeEscalation(bool toBeneficiary) public only(judge) { | |
require(escalated = true); | |
if(toBeneficiary) { | |
beneficiary.transfer(address(this).balance); | |
} else { | |
//TODO: arrange the transfer to the payee | |
payee.transfer(address(this).balance); | |
} | |
} | |
function payout() public { | |
require(testified = true); | |
//TODO: arrange the transfer to the correct address | |
beneficiary.transfer(address(this).balance); | |
} | |
function() external only(payee) { | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
contract Randomness{ | |
mapping(uint => ticket) public tickets; | |
struct ticket{ | |
uint id; | |
address buyer; | |
bytes32 hashed; | |
} | |
uint public time; | |
address public userInput; | |
bytes32 public hashed; | |
function hashIt(string memory hashMe) public returns (bytes32){ | |
hashed = sha256(bytes(hashMe)); | |
return hashed; | |
} | |
function getStuff() public{ | |
time = now; | |
userInput = msg.sender; | |
} | |
uint ticketId; | |
function addTicket() public returns(uint _id){ | |
_id = ticketId++; | |
tickets[_id] = ticket({ | |
id:_id, | |
buyer : msg.sender, | |
hashed: hashed}); | |
return tickets[_id].id; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; | |
contract TicketingDapp is Ownable, ERC721 { | |
struct Event { | |
uint eventId; | |
string name; | |
string date; | |
string eventType; | |
uint ticketPrice; | |
uint ticketSupply; | |
bool eventEnded; | |
address organizer; | |
} | |
struct eventToken{ | |
string eventName; | |
string eventDate; | |
uint ticketPrice; | |
uint ticketId; | |
} | |
uint ID; | |
mapping(uint => Event) public events; | |
address public ownerby; | |
uint ticketAmount = 1; | |
function createEvent( | |
string memory _name, | |
string memory _date, | |
string memory _eventType, | |
uint _price, | |
uint _ticketAmount | |
) public onlyOwner returns(uint _ID) { | |
_ID = ID++; | |
events[_ID] = Event ({ | |
eventId: _ID, | |
name: _name, | |
date: _date, | |
eventType: _eventType, | |
ticketPrice: _price * 1 wei, | |
ticketSupply: _ticketAmount, | |
eventEnded: false, | |
organizer: msg.sender | |
}); | |
return events[_ID].eventId; | |
} | |
function getEventDetails(uint _id) public view returns(string memory, string memory, string memory, uint, uint, uint) { | |
//get event details | |
require(events[_id].eventId == _id); | |
return (events[_id].name, | |
events[_id].date, | |
events[_id].eventType, | |
events[_id].ticketPrice, | |
events[_id].ticketSupply, | |
events[_id].eventId); | |
} | |
function endEvent(uint _id) public onlyOwner returns(bool) { | |
//sets eventEnded to true | |
return events[_id].eventEnded = true; | |
} | |
function kill(address payable _owner) public onlyOwner { | |
selfdestruct(_owner); | |
} | |
function() external payable { | |
revert(); | |
} | |
// Token SHit | |
eventToken[] public tickets; | |
constructor() public{ | |
ownerby = msg.sender; | |
} | |
string public name; | |
string public symbol; | |
function setTokenInfo(string memory _name, string memory _symbol) public{ | |
name = _name; | |
symbol = _symbol; | |
} | |
function mintTickets(uint _ticketAmount, string memory _name, string memory _date, uint _tPrice, address buyer) public{ | |
require(ownerby == msg.sender); | |
while(tickets.length < _ticketAmount){ | |
uint _id = tickets.length; | |
tickets.push(eventToken(_name, _date, _tPrice, _id)); | |
_mint(buyer, _id); | |
} | |
} | |
function sellToken(address payable buyer, uint amountofTicket, uint _id) public payable{ | |
require(events[_id].ticketSupply > amountofTicket); | |
uint256 payed = msg.value; | |
uint calculatedPrice = events[_id].ticketPrice * amountofTicket; | |
if(calculatedPrice* 1 wei == payed){ | |
mintTickets(amountofTicket, events[_id].name, | |
events[_id].date, events[_id].ticketPrice, buyer); | |
events[_id].ticketSupply = events[_id].ticketSupply - amountofTicket; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import './destruct1.sol'; | |
contract helloWorld is beGone1{ | |
function hello() public pure returns(string memory){ | |
return "Hello to the world NIGGA!!!"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
contract Retour{ | |
address payable public owner= 0xb05295337818B42707e8b8a860eA9378A23066DC; | |
function payMe() public payable { | |
if(msg.value > 150 wei){ | |
msg.sender.transfer(msg.value - 150 wei); | |
owner.transfer(150 wei); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; | |
contract testMonster is ERC721{ | |
struct Monster{ | |
string name; | |
uint level; | |
uint attackPower; | |
uint defensePower; | |
} | |
string public name = "MonsterToken"; | |
string public symbol = 'MT'; | |
Monster[] public monsters; | |
address public owner; | |
constructor() public{ | |
owner = msg.sender; | |
} | |
function createMonster(string memory _name, address _to) public{ | |
require(owner == msg.sender); | |
uint _id = monsters.length; | |
monsters.push(Monster(_name, 1, 1000, 850)); | |
_mint(_to, _id); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract Helloworld1{ | |
string name; | |
function Helloworld() public view returns(string memory){ | |
return name; | |
} | |
function itisMe(string memory yourName) public { | |
name = yourName; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
contract SimpleContract{ | |
string public name; | |
function changeName(string memory _name) public{ | |
name = _name; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract Contract1 { | |
uint public sum = 0; | |
function counter(uint _num) public{ | |
sum = sum + _num; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import './smartcontract1.sol'; | |
contract Contract2 { | |
function addnum(uint _num) public{ | |
Contract1(0x8C40fC2329aeAeC258243110b8680Cf3D9CeFDd0).counter(_num); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
contract test1 { | |
struct Event { | |
uint eventId; | |
string name; | |
string date; | |
string eventType; | |
uint ticketPrice; | |
uint ticketSupply; | |
bool eventEnded; | |
address payable organizer; | |
} | |
struct Ticket{ | |
uint id; | |
uint eventId; | |
address owner; | |
bytes32 hashed; | |
} | |
address payable public owner = 0xb05295337818B42707e8b8a860eA9378A23066DC; | |
uint ID; | |
uint ticketId; | |
bytes32 public hashed; | |
uint public allEvents; | |
string extra; | |
string[] eventArr; | |
mapping(uint => Event) public events; | |
mapping(address => bool) public admins; | |
mapping(uint => Ticket) public tickets; | |
function addTicket(uint _eventId, string memory hashMe) public returns(uint _id) { | |
_id = ticketId++; | |
hashed = sha256(bytes(hashMe)); | |
tickets[_id] = Ticket({ | |
id:_id, | |
eventId: _eventId, | |
owner : msg.sender, | |
hashed: hashed}); | |
return tickets[_id].id; | |
} | |
function buyTicket(uint _eventId, uint _ticketAmount, string memory hashMe) public payable{ | |
uint paid = msg.value; | |
owner.transfer(paid); | |
uint i; | |
while(i<= _ticketAmount){ | |
addTicket(_eventId, hashMe); | |
i++; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
contract TicketingDapp is Ownable { | |
// event object | |
struct Event { | |
uint eventId; | |
string name; | |
string date; | |
string eventType; | |
uint ticketPrice; | |
uint ticketSupply; | |
bool eventEnded; | |
address payable organizer; | |
} | |
// ticket object | |
struct Ticket{ | |
uint id; | |
uint eventId; | |
address owner; | |
bytes32 hashed; | |
} | |
// variables & mappings | |
uint ID; | |
uint ticketId; | |
bytes32 public hashed; | |
uint public allEvents; | |
string[] eventArr; | |
mapping(uint => Event) public events; | |
mapping(address => bool) public admins; | |
mapping(uint => Ticket) public tickets; | |
// modifiers | |
modifier onlyAdmin() { | |
require(admins[msg.sender] == true); | |
_; | |
} | |
// functions | |
// add new admins, addresses that can create a new event | |
function addAdmin(address newAdmin) public onlyOwner { | |
admins[newAdmin] = true; | |
} | |
// create and set event in the events mapping | |
function createEvent( | |
string memory _name, | |
string memory _date, | |
string memory _eventType, | |
uint _price, | |
uint _ticketAmount | |
) public onlyAdmin returns(uint _ID) { | |
_ID = ID++; | |
events[_ID] = Event ({ | |
eventId: _ID, | |
name: _name, | |
date: _date, | |
eventType: _eventType, | |
ticketPrice: _price * 1 wei, | |
ticketSupply: _ticketAmount, | |
eventEnded: false, | |
organizer: msg.sender | |
}); | |
eventArr.push(events[_ID].name); | |
allEvents = eventArr.length; | |
return events[_ID].eventId; | |
} | |
// get length of events mapping | |
function getAllEvents() public view returns (uint){ | |
return eventArr.length; | |
} | |
// finish event and stop selling ticket | |
function endEvent(uint _id) public onlyAdmin returns(bool) { | |
//sets eventEnded to true | |
return events[_id].eventEnded = true; | |
} | |
// create a new ticket with unique hash | |
function addTicket(uint _eventId, string memory randomness) internal returns(uint _id) { | |
_id = ticketId++; | |
hashed = sha256(bytes(randomness)); | |
tickets[_id] = Ticket({ | |
id:_id, | |
eventId: events[_eventId].eventId, | |
owner : msg.sender, | |
hashed: hashed}); | |
return tickets[_id].id; | |
} | |
// users can buy ticket by providing event id & ticket randomness (web3) | |
function buyTicket(uint _eventId, string memory randomness) public payable{ | |
uint paid = msg.value; | |
events[_eventId].organizer.transfer(paid); | |
addTicket(_eventId, randomness); | |
events[_eventId].ticketSupply = events[_eventId].ticketSupply -1; | |
} | |
// get ticket details | |
function getTicketDetails(uint _id) public view returns(uint,address, uint, bytes32) { | |
require(tickets[_id].id == _id); | |
return ( | |
tickets[_id].id, | |
tickets[_id].owner, | |
tickets[_id].eventId, | |
tickets[_id].hashed); | |
} | |
// kill contract | |
function kill(address payable _owner) public onlyOwner { | |
selfdestruct(_owner); | |
} | |
function() external payable { | |
revert(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; | |
contract TicketingDapp is Ownable, ERC721 { | |
mapping(uint => Event) public ownerToEvent; | |
struct Event { | |
string name; | |
string description; | |
uint date; | |
string eventType; | |
uint ticketPrice; | |
uint ticketSupply; | |
bool eventEnded; | |
} | |
struct eventToken{ | |
string eventName; | |
uint eventDate; | |
uint ticketPrice; | |
uint ticketId; | |
} | |
uint eventID; | |
function createEvent( | |
string memory _name, | |
string memory _desc, | |
uint _date, | |
string memory _eventType, | |
uint _price, | |
uint _ticketAmount | |
) public onlyOwner { | |
eventID = eventID++; | |
ownerToEvent[eventID] = Event ({ | |
name: _name, | |
description: _desc, | |
date: _date, | |
eventType: _eventType, | |
ticketPrice: _price, | |
ticketSupply: _ticketAmount, | |
eventEnded: false | |
}); | |
} | |
function getEventDetails() public { | |
//get event details | |
} | |
function endEvent() public onlyOwner { | |
//sets eventEnded to true | |
} | |
function kill(address payable _owner) public onlyOwner { | |
selfdestruct(_owner); | |
} | |
function() external payable { | |
revert(); | |
} | |
// Token dingens | |
string public name = ownerToEvent[0].name; | |
string public symbol = 'ETE'; | |
address public ownerby; | |
uint ticketAmount = 1; | |
eventToken[] public tickets; | |
constructor() public{ | |
ownerby = msg.sender; | |
} | |
function mintTickets(uint _ticketAmount, string memory _name, uint _date, uint _tPrice, address buyer) public{ | |
require(ownerby == msg.sender); | |
while(tickets.length < _ticketAmount){ | |
uint _id = tickets.length; | |
tickets.push(eventToken(_name, _date, _tPrice, _id)); | |
_mint(buyer, _id); | |
} | |
} | |
function sellToken(address payable buyer, uint amountofTicket) public payable{ | |
require(ownerToEvent[0].ticketSupply > amountofTicket); | |
uint256 payed = msg.value; | |
uint calculatedPrice = ownerToEvent[0].ticketPrice * amountofTicket; | |
if(calculatedPrice* 1 wei == payed){ | |
mintTickets(amountofTicket, ownerToEvent[0].name, | |
ownerToEvent[0].date, ownerToEvent[0].ticketPrice, buyer); | |
ownerToEvent[0].ticketSupply = ownerToEvent[0].ticketSupply - amountofTicket; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.7; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol"; | |
contract TicketingDapp is Ownable { | |
struct Event { | |
uint eventId; | |
string name; | |
string date; | |
string eventType; | |
uint ticketPrice; | |
uint ticketSupply; | |
bool eventEnded; | |
address organizer; | |
} | |
struct Ticket{ | |
uint id; | |
uint eventId; | |
address buyer; | |
bytes32 hashed; | |
} | |
uint ID; | |
uint ticketId; | |
uint public time; | |
address public userInput; | |
bytes32 public hashed; | |
mapping(uint => Event) public events; | |
mapping(address => bool) public admins; | |
mapping(uint => Ticket) public tickets; | |
modifier onlyAdmin() { | |
require(admins[msg.sender] == true); | |
_; | |
} | |
function addAdmin(address newAdmin) public onlyOwner { | |
admins[newAdmin] = true; | |
} | |
function createEvent( | |
string memory _name, | |
string memory _date, | |
string memory _eventType, | |
uint _price, | |
uint _ticketAmount | |
) public onlyAdmin returns(uint _ID) { | |
_ID = ID++; | |
events[_ID] = Event ({ | |
eventId: _ID, | |
name: _name, | |
date: _date, | |
eventType: _eventType, | |
ticketPrice: _price * 1 wei, | |
ticketSupply: _ticketAmount, | |
eventEnded: false, | |
organizer: msg.sender | |
}); | |
return events[_ID].eventId; | |
} | |
function getEventDetails(uint _id) public view returns(string memory, string memory, string memory, uint, uint) { | |
//get event details | |
require(events[_id].eventId == _id); | |
return (events[_id].name, | |
events[_id].date, | |
events[_id].eventType, | |
events[_id].ticketPrice, | |
events[_id].ticketSupply); | |
} | |
function endEvent(uint _id) public onlyOwner returns(bool) { | |
//sets eventEnded to true | |
return events[_id].eventEnded = true; | |
} | |
function hashIt(string memory hashMe) public returns (bytes32) { | |
hashed = sha256(bytes(hashMe)); | |
return hashed; | |
} | |
function addTicket(uint _eventId) public returns(uint _id) { | |
_id = ticketId++; | |
tickets[_id] = Ticket({ | |
id:_id, | |
eventId: events[_eventId].eventId, | |
buyer : msg.sender, | |
hashed: hashed}); | |
return tickets[_id].id; | |
} | |
function kill(address payable _owner) public onlyOwner { | |
selfdestruct(_owner); | |
} | |
function() external payable { | |
revert(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol"; | |
contract TutorialToken is ERC20 { | |
string public name = "TutorialToken"; | |
string public symbol = 'TUT'; | |
uint public decimals = 18; | |
uint public INITIAL_SUPPLY = 10000 * (10 ** decimals); | |
constructor() public { | |
_mint(msg.sender, INITIAL_SUPPLY); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract HelloWorld1 { | |
string name; | |
function HelloWorld() public view returns(string memory) { | |
return name; | |
} | |
function itIsMe(string memory yourName) public { | |
name = yourName; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
/** | |
In this exercise you have to fill in the variable visibilities for every variable declaration. | |
Simply replace XXX with the visibility type which you think is appropriate. | |
If you did everything corrrect, there will be only one red X (line 33) and you should be able to deploy | |
the contract by replacing pincode by 0. | |
*/ | |
contract father { | |
// houseAddress is accesible by the contract father and child | |
string internal houseAddress = "BigStreet 25, Amsterdam"; | |
// pincode is only accesible by the father | |
uint256 private pincode = 1234; | |
// the name is accesible by everybody | |
string public name = "James"; | |
} | |
contract child is father { | |
// should compile | |
function whereDoesMyFatherLive() public view returns(string memory) { | |
return houseAddress; | |
} | |
// should compile | |
function whatIsMyFathersName() public view returns(string memory) { | |
return name; | |
} | |
// should not compile (replace pincode by 0 to make it compile) | |
function whatIsMyFathersPincode() public pure returns(uint256) { | |
return 0; // child cannot access pincode! | |
//return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment