Created
May 19, 2020 17:26
-
-
Save maellson/f4402084b92de357a20ac5a82ccbeb30 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.2; | |
/** | |
* 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 | |
function setText (string memory myText) public { | |
text = myText; | |
setInteracted(); | |
} | |
function setNumber (uint myNumber) public { | |
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(); | |
} | |
//guarda dentro da variavel hasInteracted o valor true, pra dizer que aquele endereco interegiu dentro do contrato | |
//toda ver que um metodo acima e chamado ess funcao e executada. | |
function setInteracted()private{ | |
hasInteracted[msg.sender] = true; | |
} | |
//funcoes pure nao alteram nem consultam coisas na blockchain | |
function sum (uint num1, uint num2) public pure returns(uint){ | |
return num1 + num2; | |
} | |
//funcoes pure nao alteram nem consultam coisas na blockchain | |
function sub (uint num1, uint num2) public pure returns(uint){ | |
return num1 - num2; | |
} | |
//funcoes pure nao alteram nem consultam coisas na blockchain | |
function prod (uint num1, uint num2) public pure returns(uint){ | |
return num1 * num2; | |
} | |
//funcoes pure nao alteram nem consultam coisas na blockchain | |
function div (uint num1, uint num2) public pure returns(uint){ | |
return num1 / num2; | |
} | |
//funcoes pure nao alteram nem consultam coisas na blockchain | |
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