Skip to content

Commit 00c5da2

Browse files
Amxxfrangio
andauthored
Allow setting tokenURI for non-existent token (#4559)
Co-authored-by: Francisco <[email protected]>
1 parent 10e00c8 commit 00c5da2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

.changeset/empty-cheetahs-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': major
3+
---
4+
5+
`ERC721URIStorage`: Allow setting the token URI prior to minting.

contracts/token/ERC721/extensions/ERC721URIStorage.sol

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,9 @@ abstract contract ERC721URIStorage is IERC4906, ERC721 {
4949
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
5050
*
5151
* Emits {MetadataUpdate}.
52-
*
53-
* Requirements:
54-
*
55-
* - `tokenId` must exist.
5652
*/
5753
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
58-
if (_ownerOf(tokenId) == address(0)) {
59-
revert ERC721NonexistentToken(tokenId);
60-
}
6154
_tokenURIs[tokenId] = _tokenURI;
62-
6355
emit MetadataUpdate(tokenId);
6456
}
6557

test/token/ERC721/extensions/ERC721URIStorage.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ contract('ERC721URIStorage', function (accounts) {
5050
});
5151
});
5252

53-
it('reverts when setting for non existent token id', async function () {
54-
await expectRevertCustomError(this.token.$_setTokenURI(nonExistentTokenId, sampleUri), 'ERC721NonexistentToken', [
55-
nonExistentTokenId,
56-
]);
53+
it('setting the uri for non existent token id is allowed', async function () {
54+
expectEvent(await this.token.$_setTokenURI(nonExistentTokenId, sampleUri), 'MetadataUpdate', {
55+
_tokenId: nonExistentTokenId,
56+
});
57+
58+
// value will be accessible after mint
59+
await this.token.$_mint(owner, nonExistentTokenId);
60+
expect(await this.token.tokenURI(nonExistentTokenId)).to.be.equal(sampleUri);
5761
});
5862

5963
it('base URI can be set', async function () {

0 commit comments

Comments
 (0)