Skip to content

Instantly share code, notes, and snippets.

@marcozecchini
Created July 29, 2021 20:50
Show Gist options
  • Save marcozecchini/a429c846af1f36427f2f21ad0d50ba5b to your computer and use it in GitHub Desktop.
Save marcozecchini/a429c846af1f36427f2f21ad0d50ba5b 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.8.0+commit.c7dfd78e.js&optimize=true&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.0;
/**
* @dev This is an example contract implementation of NFToken with metadata extension.
*/
import "/contracts/MyCIHEAMToken.sol";
contract SimpleSale {
MyCIHEAMToken myToken;
uint public NFTid;
uint public weiPrice;
address payable public beneficiary;
bool ended = false;
// Events that will be emitted on changes.
event SaleEnded(address winner, uint amount);
constructor(
uint _weiPrice,
uint _NFTid,
address _tokenSC
) {
weiPrice = _weiPrice;
NFTid = _NFTid;
myToken = MyCIHEAMToken(_tokenSC);
beneficiary = payable (myToken.ownerOf(NFTid));
}
function pay() public payable {
require(
msg.value == weiPrice,
"Il prezzo non coincide"
);
require(!ended, "auctionEnd has already been called.");
// 2. Effects
ended = true;
emit SaleEnded(msg.sender,msg.value);
// 3. Interaction
beneficiary.transfer(msg.value);
myToken.safeTransferFrom(beneficiary, msg.sender, NFTid);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment