Skip to content

Instantly share code, notes, and snippets.

@rpaskin
Created April 1, 2024 00:27
Show Gist options
  • Save rpaskin/60401f860795b49e79b0e4cdf34a3f56 to your computer and use it in GitHub Desktop.
Save rpaskin/60401f860795b49e79b0e4cdf34a3f56 to your computer and use it in GitHub Desktop.
M2A5 Código solidity para um "NFT" de uma latinha de refrigerante
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
contract RefriToken {
uint public id_da_latinha = 4321; // identificador da latinha
address public dono = msg.sender; // dono inicial da latinha é quem cria o contrato
uint public quantos_ml = 310; // volume de liquido na latinha quantos_ml
function comprar() public payable {
require(msg.value == 0.02 ether); // tem que receber 0.02 ether ou 20000000 Gwei
require(quantos_ml > 0); // a latinha só pode ser vendida se não estiver vazia
payable(dono).transfer(address(this).balance); // enviar saldo ao dono anterior
dono = msg.sender; // registrar novo dono, ou seja, quem está comprando
}
function beber(uint bebidos_ml) public returns (uint restante_ml) {
require(msg.sender == dono); // apenas o dono pode beber
require(bebidos_ml <= quantos_ml); // ele não pode beber mais liquido do que tem na latinha
quantos_ml = quantos_ml - bebidos_ml; // diminui volume na latinha
return quantos_ml; // retorna novo volume calculado
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment