Skip to content

Instantly share code, notes, and snippets.

@Manasse228
Created May 27, 2018 13:46
Show Gist options
  • Save Manasse228/8e161537acf356666329b5f53d8fcd65 to your computer and use it in GitHub Desktop.
Save Manasse228/8e161537acf356666329b5f53d8fcd65 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=
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];
}
}
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;
}
}
}
pragma solidity ^0.4.19;
contract Crowdfunding {
uint public minimumEntryFee;
uint public campagneDeadline;
uint public projectProposalDeadLine;
uint public winningVote;
address winningProject;
address owner;
constructor(uint min, uint camDeadline, uint projProDeadLine) public{
require(campagneDeadline >= projectProposalDeadLine);
minimumEntryFee = min;
campagneDeadline = now + camDeadline * 1 seconds;
projectProposalDeadLine = now + projProDeadLine * 1 seconds;
owner = msg.sender;
}
struct Project{
string name;
string url;
bool exist;
address ad;
uint amount;
}
mapping(address => Project) projectMap;
address[] projectsAddress;
function createProject(string name, string url) public payable returns(bool){
require(msg.value > minimumEntryFee);
require(now < projectProposalDeadLine);
if(!projectMap[msg.sender].exist){
projectMap[msg.sender] = Project(name, url, true, msg.sender, 0);
projectsAddress.push(msg.sender);
return true;
}
return false;
}
function vote(address projAd) public payable {
require(now > projectProposalDeadLine);
require(msg.value > 0);
require(projectMap[projAd].exist);
projectMap[projAd].amount += msg.value;
if(winningVote < projectMap[projAd].amount){
winningVote = projectMap[projAd].amount;
winningProject = projAd;
}
}
function kill() public {
if(now > campagneDeadline){
selfdestruct(winningProject);
}
}
}
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);
}
}
pragma solidity ^0.4.19;
contract Event {
event myFirstEvent(string, uint);
}
pragma solidity ^0.4.19;
contract Function {
bytes1 test = 10;
}
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];
}
}
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++;
}
}
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;
}
}
{
"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"
}
]
}
}
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