Skip to content

Instantly share code, notes, and snippets.

@GalloDaSballo
Created May 26, 2021 14:58
Show Gist options
  • Save GalloDaSballo/4d00b79b72816fa0e1969ea39cd79db3 to your computer and use it in GitHub Desktop.
Save GalloDaSballo/4d00b79b72816fa0e1969ea39cd79db3 to your computer and use it in GitHub Desktop.
ERC721 Demo of Plane Tickets
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
// Import OpenZeppelin ERC721
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/access/Ownable.sol";
// Inherit from OpenZeppelin ERC721
contract PlaneTicket is ERC721, Ownable {
// Add our own features (planId, seatId, timeStamp)
// The function called on Token Creation
constructor() public ERC721("PlaneTicket", "AIRLINETICKET") {
_setBaseURI("https://tickets.info/"); // Base URI is the URL you use to display data for the NFT
}
// In the "real world" you would have the shop, mint a token after a sale
function mint(uint256 tokenId) public onlyOwner {
_mint(msg.sender, tokenId); // Create the TOKEN and send it to whoever called the contract
_setTokenURI(tokenId, uint2str(tokenId));
}
function uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len - 1;
while (_i != 0) {
bstr[k--] = byte(uint8(48 + _i % 10));
_i /= 10;
}
return string(bstr);
}
}
// Very expensive to store all the data on mainnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment