Skip to content

Instantly share code, notes, and snippets.

@hendrikebbers
Last active May 24, 2024 21:58
Show Gist options
  • Save hendrikebbers/98b51837f39603083a026793b1d8eb56 to your computer and use it in GitHub Desktop.
Save hendrikebbers/98b51837f39603083a026793b1d8eb56 to your computer and use it in GitHub Desktop.
Idea for NFT that can be used in Games
/// GNFT - GameNFT
/// The idea is based on ERC-721 (NFT).
/// The given interfaces depend on ERC721 and ERC165 (description can be found at the end of this doc)
/// The idea is that a token is always bound to an app (application) that is defined by an address.
/// Next to that the application owner (application address) can lock/unlock a token.
/// By doing so a token can not be transfered to another owner while it is "in use".
/// Let's assume you are playing a trading card game and attend an official tournament.
/// While the tournament happens you should not be allowed to to sell any tokens that are used as your playing cards
/// in that tournament.
/// Another example would be a custom graffiti that you own in a skateboard game. When you put that graffiti on
/// your skateboard the token will be locked. By doing so the application does not check all the time when you
/// start the game that all your tokens are still belong to you. Once you remove it from the board it will be unlocked.
/// Since a goal of this proposal is to create tokens that can be shared between several games the locking
/// of a token always happens per application. The mentioned graffiti could for example be used in 2 different games.
/// Here the token must be locked be each and every game that uses it. Only if all games have unlocked the token
/// it can be sold / transfered.
/// In games tokens can be used in different forms. A token could be a card in an TCG, a graffiti in a skateboard game
/// or a weapon in a roleplaying game. To allow that tokens can be reused in other games tags are introduced.
/// Tags are similar to mimetypes and define the content of the token. A basic token can be a flat image. That image
/// can be used in a lot of games to style any item. It can be added to the skin of a car or a skateboard for example.
/// More complex types could be a sound or maybe even a 3d model.
interface GNFT is ERC721 {
function balanceOfByApplication(address _owner, address _application) external view returns (uint256);
function balanceOfApplication(address _application) external view returns (uint256);
function applicationOf(uint256 _tokenId) external view returns (address);
function balanceOfByTag(address _owner, string _tag) external view returns (uint256);
// Only for application (and contract admin)
function lock(address _application, uint256 indexed _tokenId);
function unlock(address _application, uint256 indexed _tokenId);
// Only for contract admin
function transferFromApplication(address _fromApplication, address _toApplication, uint256 _tokenId);
function registerApplication(address _application, string name, string _uri);
function deregisterApplication(address _application);
}
interface GNFTEnumerable /* is GNFT /* {
function tokenByIndex(address _application, uint256 _index) external view returns (uint256);
function tokenOfOwnerByIndex(address _application, address _owner, uint256 _index) external view returns (uint256);
function tokenOfOwnerByTag(address _owner, string tag, uint256 _index) external view returns (uint256);
}
interface GNFTMetadata /* is GNFT */ {
function name(address _application) external view returns (string _name);
function applicationURI(address _application) external view returns (string _uri);
function description(address _application) external view returns (string _name);
function application(uint256 _tokenId) external view returns (address _application);
function isLocked(uint256 indexed _tokenId) returns (bool _locked);
function lockedBy(uint256 indexed _tokenId) returns (address[] _applications);
function tokenURI(uint256 _tokenId) external view returns (string _uri);
function getTags() external view returns (string[] _tags)
}
/// ERC-721 and ERC-165
/// The following part are the interfaces defined by that specs (mostly for me to check it)
/// ERC-721 Non-Fungible Token Standard
/// See https://eips.ethereum.org/EIPS/eip-721
/// Note: the ERC-165 identifier for this interface is 0x80ac58cd.
interface ERC721 is ERC165 {
event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId);
event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
function balanceOf(address _owner) external view returns (uint256);
function ownerOf(uint256 _tokenId) external view returns (address);
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
function transferFrom(address _from, address _to, uint256 _tokenId) external payable;
function approve(address _approved, uint256 _tokenId) external payable;
function setApprovalForAll(address _operator, bool _approved) external;
function getApproved(uint256 _tokenId) external view returns (address);
function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
/// ERC-165: Standard Interface Detection
/// See https://eips.ethereum.org/EIPS/eip-165
interface ERC165 {
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment