Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The seller approves the contract address to act on their behalf.
- The token is listed as available for sale in the marketplace.
- Then, when the buyer wants to buy the token, the contract transfers the token from the seller to the buyer, and transfers the payment from buyer to seller.
- struct Token {
- uint id;
- uint price;
- uint prevPrice;
- bool forSale;
- }
- function buyMarketplaceToken(uint _tokenId) public payable whenNotPaused() isForSale(_tokenId) {
- address ticketOwner = ownerOf(_tokenId);
- require(msg.value >= tokens[_tokenId].price, "It costs more!");
- ticketOwner.transfer(msg.value);
- safeTransferFrom(ticketOwner, msg.sender, _ticketId);
- clearApproval(this, _ticketId);
- tokens[_tokenId].forSale = false;
- }
- function addTokenForSale(uint _tokenId, uint newPrice) public onlyOwner(_tokenId) whenNotPaused() {
- tokens[_tokenId].forSale = true;
- tokens[_tokenId].prevPrice = tokens[_tokenId].price;
- tokens[_tokenId].price = newPrice;
- approve(address(this), _tokenId);
- emit TokenOnSale(_tokenId, newPrice);
- }
- function removeTokenForSale(uint _tokenId) public onlyOwner(_tokenId) whenNotPaused() {
- tokens[_tokenId].forSale = false;
- tokens[_tokenId].price = tokens[_tokenId].prevPrice;
- clearApproval(address(this), _tokenId);
- emit TokenOffSale(_tokenId, tokens[_tokenId].prevPrice);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement