Created
May 21, 2020 14:27
-
-
Save maellson/f2ad09829ec5b4933e86c2b7b6ba6188 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.17+commit.d19bba13.js&optimize=false&gist=
This file contains 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 GuardaLoteria { | |
uint numeroSorteado; | |
function set(uint enviado) public{ | |
numeroSorteado = enviado; | |
} | |
function get() public view returns (uint) { | |
return numeroSorteado; | |
} | |
} |
This file contains 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.17; | |
/** | |
* The contractName contract does this and that... | |
*/ | |
contract HelloWorld { | |
string public text;//defeiniu uma string como sendo publica de acesso global | |
uint public number;//definiu uma variavel numerica | |
address public userAddress;//definiu uma variavel do tipo endereco | |
bool public answer;// definiu uma variavel booleana | |
//mapping (address => bool) public hasInteracted;//definiu uma variavel mapeada que informa se um endereco interagiu no contrato (modelo_1) | |
mapping (address => uint) public hasInteracted;//essa variavel recebe a quantidade de vezes em que houve interacao no contrato(modelo_2) | |
function setText (string memory myText) public { | |
text = myText; | |
setInteracted(); | |
} | |
function setNumber (uint myNumber) public payable { | |
require (msg.value >= 1 ether, "Insufficient ETH sent."); | |
number = myNumber; | |
setInteracted(); | |
} | |
//esta funcao ler de imediato de qual endereco partiu a mensagem ou os termos do contrato. | |
function setUserAddress() public { | |
userAddress = msg.sender; | |
setInteracted(); | |
} | |
//variaveis booleana so aceitam dois valores true ou false, caso seja inserido outro valor, sera interpretado como true | |
function setAnswer (bool myAnswer) public { | |
answer = myAnswer; | |
setInteracted(); | |
} | |
//(modelo_1)guarda dentro da variavel hasInteracted o valor true, pra dizer que aquele endereco interegiu dentro do contrato | |
//(modelo_2) Incrementa o valor da varivael para contar quantas vezes houve interacoes no contrato. | |
//toda ver que um metodo acima e chamado ess funcao e executada. | |
function setInteracted()private{ | |
//hasInteracted[msg.sender] = true; //modelo_1 | |
hasInteracted[msg.sender] +=1; //modelo_2 | |
} | |
//funcoes pure nao alteram nem consultam coisas na blockchain e sao gratuitas | |
function sum (uint num1, uint num2) public pure returns(uint){ | |
return num1 + num2; | |
} | |
function sub (uint num1, uint num2) public pure returns(uint){ | |
return num1 - num2; | |
} | |
function prod (uint num1, uint num2) public pure returns(uint){ | |
return num1 * num2; | |
} | |
function div (uint num1, uint num2) public pure returns(uint){ | |
return num1 / num2; | |
} | |
function power (uint num1, uint num2) public pure returns(uint){ | |
return num1 ** num2; | |
} | |
//funcoes do tipo view fazem consulta na blockchain. ela esta consultando o valor de number | |
function sumStored (uint num1) public view returns(uint){ | |
return num1 + number; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment