Here's my attempt for ERC721, but perhaps could be improved.
pragma solidity ^0.4.24;
import "./ERC721Token.sol";
contract DefaultERC721TokenURI is ERC721Token {
string private tokenURI_ = "";
constructor(string _tokenURI)
public
{
require(bytes(_tokenURI).length > 0);
tokenURI_ = _tokenURI;
}
/**
* @dev Returns a default URI for every tokenId unless a specific URI is set
* @param _tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 _tokenId)
public
view
returns (string)
{
if (bytes(tokenURIs[_tokenId]).length != 0) {
return super.tokenURI(_tokenId);
}
return tokenURI_;
}
}
I can take it up @shrugs. Your implementation helps and will get back on this.
Hey @logeekal, there's actually been a new related proposal that I prefer: https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1745.
The idea is to generate an automatic URI for each token that is the concatenation of a base URI and the token id. I feel like this provides a more complete solution to the problem.
There is no one working on that at the moment. Would you like to? There is already a library to convert numbers to strings that we built for this purpose in https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1746.
Thanks @frangio for pitching in and pointed me in right direction. I am here to learn and can certainly take it up. I may need a little help on the way though.
thanks again.
Cool! Closing in favor of #1745 then.
Most helpful comment
Hey @logeekal, there's actually been a new related proposal that I prefer: https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1745.
The idea is to generate an automatic URI for each token that is the concatenation of a base URI and the token id. I feel like this provides a more complete solution to the problem.
There is no one working on that at the moment. Would you like to? There is already a library to convert numbers to strings that we built for this purpose in https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1746.