-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERC721 "automatic" token URI #1745
Comments
* Feature Issue #1745 * Feature Issue #1745 remove whitespace in contract * Feature Issue #1745 fix Solidity linter issues * Feature Issue #1745 fix JS lint issues * Update contracts/drafts/Strings.sol Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com> * Update contracts/drafts/Strings.sol Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com> * Update contracts/drafts/Strings.sol Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com> * Updates based on PR feedback * Remove trailing whitespace * Update tests based on @nventuro feedback * Removed return name * Rename length as suggested * Rename temp variables in uint256ToString * Renamed bytes variable to buffer * Change concatenate to use abi.encodePacked * Moved OraclizeAPI reference to unit256ToString * Add emoji concat test * Remove concatenate * Remove concatenate from StringsMock and test * Rename function to fromUint256 * Update StringsMock.sol
Note that for concatenation of the base URI with the tokenId string we will use |
As discussed in #1163 , I can take this up. |
@logeekal Will your implementation make the baseTokenURI settable? I think this would be good, in the event that the URL needs to change. Is this code in a branch anywhere? |
Hello @pointtoken, I will start implementation today so no code branch as of now. And I am assuming that it should be settable so that everyone can set there own URI probably in constructor of their contract so that they do not have to do that with every mint operation. What do you think @abcoathup, In Blockhorses I see that you have hard-coded it, so to be generic I also think it should be settable as well. |
Hi @logeekal I agree, I think that a private There should also be an internal setter function, so tokens inheriting from this contract can create a mechanism to change the _baseTokenURI as required. In PeepethBadges.sol we had the private state variable |
Once one embraces the idea of offchain metadata for an NFT, one is embracing the idea that the NFT has data which could change. As such, the URL itself of the metadata needs to be change-able. Classic example: the company that created the contract gets sold or folds or who knows what, and the the metadata server itself is no longer available. There could be a scenario where a new metadata server is deployed, thus the need to update the tokenURI, keeping the NFT's metadata URL to be accessed onchain. Otherwise, that contract become much less usable for people who hold the actual NFT. |
Here's some code, although there may be better ways now: ` string public tokenURIPrefix = "https://api.nft.com/";
function tokenURI(uint256 _tokenId) public view returns (string) {
` |
Hi @pointtoken There is already a Strings library in drafts with a I suggest that the That way, inheriting contracts have the option to create an I agree that having metadata off chain and based on a URI rather than being content addressable means that the metadata is centralized. |
ok, as long that it is easy to make public and settable by an owner of the contract |
Just curious the status of this feature @abcoathup @logeekal -- timeframe when it might get merged to master? |
@pointtoken I haven't done any more beyond the Strings library. I would love to see this implemented. @logeekal are you still working on this? |
@nachomazzara from Decentraland commented that it is currently not possible for users to easily implement this feature (which they need) due to If @logeekal will not end up tackling this, someone else should do it: we already have a concrete design proposal, and many users would be benefited by this feature. |
I apologize that I completely forgot about this and got involved in other task. I will take it up next week and get back with updates. |
To put in here what we thought (omit non-changed code): pragma solidity ^0.5.0;
import "../../GSN/Context.sol";
import "./ERC721.sol";
import "./IERC721Metadata.sol";
import "../../introspection/ERC165.sol";
contract ERC721Metadata is Context, ERC165, ERC721, IERC721Metadata {
//...
// Base Token URI
string private _baseTokenURI;
//...
// **PROPOSED CHANGE**:
// - `external` to `public` (Allow 'super')
// - Concat baseURI with tokenURI
function tokenURI(uint256 tokenId) public view returns (string memory) {
return string(abi.encodePacked(_baseTokenURI, _tokenURI(tokenId)));
}
/**
* @dev Internal returns an URI for a given token ID.
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function _tokenURI(uint256 tokenId) internal view returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
return _tokenURIs[tokenId];
}
/**
* @dev Internal function to set the base token URI.
* @param uri string base URI to assign
*/
function _setBaseTokenURI(string memory uri) internal {
_baseTokenURI = uri;
}
} It continues following the The idea is not only to use the
I'm wondering if we should emit an event once the |
Added a PR |
Hi @nachomazzara, Thank you 🙏 This solution gives flexibility, e.g. allows saving an IPFS hash, with the base URI being an IPFS gateway URI, where the base URI can be changed to support a change of IPFS gateway. An example ERC721 token using this functionality as I envisaged could then be:
|
Reopening as #1970 doesn't implement an "automatic" token URI. (but is the basis for adding this functionality. e.g.:
Should we be creating an |
As mentioned in #2154, we want to bundle this by default in |
🧐 Motivation
Current ERC721 minting with token URI requires manually specifying the URI per token.
To reduce gas cost, the OpenSea example uses concatenation of a base token URI and the tokenID. (
TradeableERC721Token.sol
)📝 Details
We want to provide an ERC721 extension
ERC721DefaultURI
with a base URI parameter, which overridesERC721Metadata
'stokenURI()
with the concatenation. To discuss the API please comment on the forum thread about this.The text was updated successfully, but these errors were encountered: