Skip to content

Commit

Permalink
add simple catch-all implementation for the metadata URI interface
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiRo-at committed Dec 13, 2019
1 parent 20642cc commit 859f6e7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
38 changes: 38 additions & 0 deletions contracts/token/ERC1155/ERC1155MetadataURI_CatchAll.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pragma solidity ^0.5.9;

import "./ERC1155.sol";
import "./IERC1155MetadataURI.sol";
import "../../introspection/ERC165.sol";

contract ERC1155MetadataURI_CatchAll is ERC165, ERC1155, IERC1155MetadataURI {
// Catch-all URI with placeholders, e.g. https://example.com/{locale}/{id}.json
string private _uri;

/*
* bytes4(keccak256('uri(uint256)')) == 0x0e89341c
*/
bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c;

/**
* @dev Constructor function
*/
constructor (string memory uri) public {
_uri = uri;
emit URI(_uri, 0);

// register the supported interfaces to conform to ERC1155 via ERC165
_registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI);
}

/**
* @notice A distinct Uniform Resource Identifier (URI) for a given token.
* @dev URIs are defined in RFC 3986.
* The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema".
* param id uint256 ID of the token to query (ignored in this particular implementation,
* as an {id} parameter in the string is expected)
* @return URI string
*/
function uri(uint256 /*id*/) external view returns (string memory) {
return _uri;
}
}
11 changes: 11 additions & 0 deletions contracts/token/ERC1155/IERC1155MetadataURI.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.5.0;

import "./IERC1155.sol";

/**
* @title ERC-1155 Multi Token Standard basic interface, optional metadata URI extension
* @dev See https://eips.ethereum.org/EIPS/eip-1155
*/
contract IERC1155MetadataURI is IERC1155 {
function uri(uint256 id) external view returns (string memory);
}

0 comments on commit 859f6e7

Please sign in to comment.