Created
May 26, 2018 21:48
-
-
Save Manasse228/ffab23e35d6642761dd9f3bfe4f9c449 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.4.23+commit.124ca40d.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.4.19; | |
contract Array { | |
uint[5] staticArray = [12, 45, 56, 7]; | |
uint[] dynamicArray; | |
string elle = "jeune fille"; | |
function getStaticArray() external returns(uint){ | |
staticArray[2] = 1000; | |
return staticArray[2]; | |
} | |
function getDynamicArray() public returns(uint){ | |
dynamicArray = new uint[](10); | |
dynamicArray.push(10); | |
return dynamicArray[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.4.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. | |
function Ballot(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 constant 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.4.19; | |
contract Crowdfunding { | |
uint minimumEntryFee = 2; | |
uint campagneDeadline = 5000; | |
uint projectProposalDeadLine = 125; | |
address owner = 0x44d4470d66193c5789ebd99937b8d455d8de144f; | |
struct Project{ | |
string name; | |
string url; | |
uint entryFee; | |
address ad; | |
uint amountVote; | |
} | |
mapping(address => Project) projectMap; | |
address[] projectsAddress; | |
// Check deadLine | |
modifier checkDeadline(uint deadline){ | |
if(deadline > 0) | |
_; | |
} | |
// Check user balance | |
modifier checkBalance(){ | |
if(msg.value > 0) | |
_; | |
} | |
function deadline() private { | |
projectProposalDeadLine--; | |
campagneDeadline--; | |
} | |
function createProject(string name, string url, uint entryFee) public payable checkDeadline(projectProposalDeadLine) { | |
if(entryFee >= minimumEntryFee){ | |
projectMap[msg.sender] = Project(name, url, entryFee, msg.sender, 0); | |
projectsAddress.push(msg.sender); | |
deadline(); | |
msg.sender.transfer(entryFee); | |
} | |
} | |
function vote(address projAd) public checkBalance() payable { | |
if(projectProposalDeadLine <= 0){ | |
projectMap[projAd].amountVote = projectMap[projAd].amountVote + msg.value; | |
deadline(); | |
} | |
} | |
function checkCampagneOver() checkDeadline(campagneDeadline) public{ | |
if(campagneDeadline <= 0){ | |
uint topScore; | |
address projectAddress; | |
for(uint j=0;j<projectsAddress.length ;j++){ | |
address currentProjectAddress = projectsAddress[j]; | |
Project memory project = projectMap[currentProjectAddress] ; | |
if( topScore < project.amountVote ){ | |
topScore = project.amountVote; | |
projectAddress = project.ad; | |
break; | |
} | |
} | |
Project memory selectProject = projectMap[projectAddress]; | |
selectProject.ad.transfer(selectProject.amountVote+selectProject.entryFee); | |
} | |
} | |
} | |
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.19; | |
contract Enumeration { | |
enum RegionList { | |
Maritime, | |
Plateaux, | |
Centrale, | |
Kara, | |
Savanes | |
} | |
RegionList region; | |
function getRegion() external returns(uint myRegion){ | |
region = RegionList.Kara; | |
return uint(region); | |
} | |
} |
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.19; | |
contract Event { | |
event myFirstEvent(string, uint); | |
} |
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.19; | |
contract Function { | |
bytes1 test = 10; | |
} |
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.19; | |
contract Mapping { | |
mapping (uint => address) listAdress; | |
mapping (uint => mapping(string => address)) multiListAdress; | |
uint account; | |
uint account1; | |
function setAdress(address adr) external { | |
listAdress[account] = adr; | |
account++; | |
} | |
function setAdress2(address add, bytes names) external{ | |
string memory convert = string(names); | |
multiListAdress[account1][convert] = add; | |
account1++; | |
} | |
function getAdress(uint count) external view returns(address){ | |
return listAdress[count]; | |
} | |
function getAdressByName(uint count, bytes byt) view external returns(address){ | |
string memory name = string(byt); | |
return multiListAdress[count][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.4.19; | |
contract Modifier { | |
bool test = false; | |
uint a=1; | |
modifier testMe(){ | |
if(test){ | |
a++; | |
}else{ | |
a=20; | |
} | |
_; | |
} | |
function geth() testMe() external returns(uint resultat){ | |
return a++; | |
} | |
} |
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.19; | |
contract Operation { | |
uint storeData; | |
bool a; | |
bool constant test = true; | |
string b; | |
int internal statedVariable; | |
int private privateVariable; | |
int public publicVariable; | |
struct voiture{ | |
string color; | |
uint age; | |
string gas; | |
bool fourWheel; | |
} | |
voiture benz = voiture("Yellow", 12, "Diesel", true); | |
function set(string x){ | |
b = x; | |
} | |
function get() constant returns(string stringvar) | |
{ | |
return b; | |
} | |
} |
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
{ | |
"accounts": { | |
"account{1}": "0x14723a09acff6d2a60dcdf7aa4aff308fddc160c" | |
}, | |
"linkReferences": {}, | |
"transactions": [ | |
{ | |
"timestamp": 1526255469962, | |
"record": { | |
"value": "0", | |
"parameters": [], | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"contractName": "Operation", | |
"bytecode": "608060405234801561001057600080fd5b5060e28061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080546014029050905600a165627a7a72305820faaa8a973c9f9f7a854032ef2e6ebac2842305c397c4bd2d7317ac347c43d62c0029", | |
"linkReferences": {}, | |
"name": "", | |
"type": "constructor", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255484438, | |
"record": { | |
"value": "0", | |
"parameters": [ | |
"12" | |
], | |
"to": "created{1526255469962}", | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"name": "set", | |
"type": "function", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255825530, | |
"record": { | |
"value": "0", | |
"parameters": [], | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"contractName": "Operation", | |
"bytecode": "608060405234801561001057600080fd5b5060e28061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080546014029050905600a165627a7a72305820faaa8a973c9f9f7a854032ef2e6ebac2842305c397c4bd2d7317ac347c43d62c0029", | |
"linkReferences": {}, | |
"name": "", | |
"type": "constructor", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255832526, | |
"record": { | |
"value": "0", | |
"parameters": [ | |
"12" | |
], | |
"to": "created{1526255825530}", | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"name": "set", | |
"type": "function", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255900538, | |
"record": { | |
"value": "0", | |
"parameters": [], | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"contractName": "Operation", | |
"bytecode": "608060405234801561001057600080fd5b5060e28061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080546014029050905600a165627a7a7230582032dae06380afe5f51176314b8280d13a4eb4dd88f67a69cc20801872e4aa5f330029", | |
"linkReferences": {}, | |
"name": "", | |
"type": "constructor", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255922946, | |
"record": { | |
"value": "0", | |
"parameters": [ | |
"10" | |
], | |
"to": "created{1526255900538}", | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"name": "set", | |
"type": "function", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255928210, | |
"record": { | |
"value": "0", | |
"parameters": [], | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"contractName": "Operation", | |
"bytecode": "608060405234801561001057600080fd5b5060e28061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080546014029050905600a165627a7a7230582032dae06380afe5f51176314b8280d13a4eb4dd88f67a69cc20801872e4aa5f330029", | |
"linkReferences": {}, | |
"name": "", | |
"type": "constructor", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255959112, | |
"record": { | |
"value": "0", | |
"parameters": [ | |
"100" | |
], | |
"to": "created{1526255928210}", | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"name": "set", | |
"type": "function", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526255965612, | |
"record": { | |
"value": "0", | |
"parameters": [], | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"contractName": "Operation", | |
"bytecode": "608060405234801561001057600080fd5b5060e28061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080546014029050905600a165627a7a7230582032dae06380afe5f51176314b8280d13a4eb4dd88f67a69cc20801872e4aa5f330029", | |
"linkReferences": {}, | |
"name": "", | |
"type": "constructor", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526256073578, | |
"record": { | |
"value": "0", | |
"parameters": [ | |
"1" | |
], | |
"to": "created{1526255965612}", | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"name": "set", | |
"type": "function", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526256083568, | |
"record": { | |
"value": "10", | |
"parameters": [], | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"contractName": "Operation", | |
"bytecode": "608060405234801561001057600080fd5b5060e28061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080546014029050905600a165627a7a7230582032dae06380afe5f51176314b8280d13a4eb4dd88f67a69cc20801872e4aa5f330029", | |
"linkReferences": {}, | |
"name": "", | |
"type": "constructor", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526256090240, | |
"record": { | |
"value": "0", | |
"parameters": [], | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"contractName": "Operation", | |
"bytecode": "608060405234801561001057600080fd5b5060e28061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080546014029050905600a165627a7a7230582032dae06380afe5f51176314b8280d13a4eb4dd88f67a69cc20801872e4aa5f330029", | |
"linkReferences": {}, | |
"name": "", | |
"type": "constructor", | |
"from": "account{1}" | |
} | |
}, | |
{ | |
"timestamp": 1526256098312, | |
"record": { | |
"value": "0", | |
"parameters": [ | |
"12" | |
], | |
"to": "created{1526256090240}", | |
"abi": "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798", | |
"name": "set", | |
"type": "function", | |
"from": "account{1}" | |
} | |
} | |
], | |
"abis": { | |
"0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798": [ | |
{ | |
"constant": false, | |
"inputs": [ | |
{ | |
"name": "set_value", | |
"type": "uint256" | |
} | |
], | |
"name": "set", | |
"outputs": [], | |
"payable": false, | |
"stateMutability": "nonpayable", | |
"type": "function" | |
}, | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "get", | |
"outputs": [ | |
{ | |
"name": "retval", | |
"type": "uint256" | |
} | |
], | |
"payable": false, | |
"stateMutability": "view", | |
"type": "function" | |
} | |
] | |
} | |
} |
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.19; | |
contract Structure { | |
struct Employe{ | |
string nom; | |
string prenom; | |
uint salary; | |
bool sexe; | |
} | |
Employe emp = Employe("EKLOU", "Viviane", 5000, true); | |
function setNom(Employe empl, string nom) private{ | |
empl.nom = nom; | |
} | |
function setPrenom(Employe empl, string prenom) private{ | |
empl.prenom = prenom; | |
} | |
function setSalary(Employe empl, uint salary) private{ | |
empl.salary = salary; | |
} | |
function get() public view returns(uint salary41){ | |
return emp.salary; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment