Skip to content

feat: getnftinfo will return its metadata and creation time#225

Closed
arianejasuwienas wants to merge 5 commits intomainfrom
198-nft-metada-and-creation-time
Closed

feat: getnftinfo will return its metadata and creation time#225
arianejasuwienas wants to merge 5 commits intomainfrom
198-nft-metada-and-creation-time

Conversation

@arianejasuwienas
Copy link
Copy Markdown
Contributor

Description:

A call to the getNonFungibleTokenInfo method on the HTS address (0x167) will now correctly populate the "metadata" and "creationTime" fields.

Related issue(s):

Fixes #198

Notes for reviewer:

Until now, these fields were mocked because they were not supported by IERC721 and required a direct implementation.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@arianejasuwienas arianejasuwienas added the feature Enhancing an existing feature driven by business requirements. Typically backwards compatible. label Jan 30, 2025
@arianejasuwienas arianejasuwienas self-assigned this Jan 30, 2025
@arianejasuwienas arianejasuwienas force-pushed the 198-nft-metada-and-creation-time branch from 7134471 to 012735b Compare January 30, 2025 12:58
@arianejasuwienas arianejasuwienas changed the title feat: getnftinfo will return its metadata and creation time (#164) feat: getnftinfo will return its metadata and creation time (#198) Jan 30, 2025
@arianejasuwienas arianejasuwienas marked this pull request as ready for review January 31, 2025 08:16
@arianejasuwienas arianejasuwienas requested a review from a team as a code owner January 31, 2025 08:16
Copy link
Copy Markdown
Contributor

@acuarica acuarica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for sending this.

Comment on lines +469 to +470
string memory metadata = mirrorNode().getNftMetadata(address(this), serialId);
string memory createdTimestamp = mirrorNode().getNftCreatedTimestamp(address(this), serialId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should unify these two calls to the MN into one, maybe something like getNftMetadataAndCreatedTimestamp, and extract both fields.

src/index.js Outdated
tokenId,
blockNumber,
nrequestedSlot,
atob(metadata),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Buffer.from(metadata, 'base64').toString() to be consistent with similar code below.

src/index.js Outdated
`Failed to get the metadata of the NFT ${tokenId}#${serialId}`
);
const timestamp = Number(created_timestamp.split('.')[0]).toString(16).padStart(64, '0');
const metadataEncoded = Buffer.from(metadata).toString('hex');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean

Suggested change
const metadataEncoded = Buffer.from(metadata).toString('hex');
const metadataEncoded = Buffer.from(metadata, 'base64').toString('hex');

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the metadata is just a raw, encoded value - it can be any string. I'm simply calculating the bytes of the string without doing anything else to it. @acuarica

@arianejasuwienas arianejasuwienas force-pushed the 198-nft-metada-and-creation-time branch from 18fb2c1 to 1f1b731 Compare February 24, 2025 10:58
@arianejasuwienas
Copy link
Copy Markdown
Contributor Author

@acuarica Thank you for review! I've applied your suggestions (except for this one: #225 (comment), where I've left a comment).

const metadataEncoded = Buffer.from(metadata, 'utf-8').toString('hex');
const metadataLength = metadata.length.toString(16).padStart(64, '0');
const stringTypeIndicator = '40'.padStart(64, '0');
const bytes = `${timestamp}${stringTypeIndicator}${metadataLength}${metadataEncoded}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this work? does this request occupy multiple slots? Do we have a unit test in ERC721.t.sol to cover this? If not, we should add one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below are the contents of the memory starting at this slot:

https://github.com/hashgraph/hedera-forking/pull/225/files#diff-6b0194add020b3f0fb2f67f2eac675de98278882a61d442e1c7a2b9bd97b41d4R517

It is a tuple containing an int64 followed by a string, which means it may occupy more than one slot. Note that IERC721 does not use it; instead, tokenURI is stored in a separate slot. I haven't changed that for now because it makes sense - we avoid having to decode the metadata value every time tokenURI is queried. Let me know if we want to change that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is this implementation with dedicated tokenUri slot removed:

#250

One test would need to be rewritten, since we have no byte comparating function prepared yet to handle this operation; since I'm not sure if we want to go this way I've skipped this test instead of rewriting it for now.

Copy link
Copy Markdown
Contributor Author

@arianejasuwienas arianejasuwienas Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged this (#250), so all changes are already included in this PR. @acuarica

I also fixed this broken test for the tokenUri.

@arianejasuwienas arianejasuwienas changed the title feat: getnftinfo will return its metadata and creation time (#198) feat: getnftinfo will return its metadata and creation time Mar 5, 2025
@arianejasuwienas arianejasuwienas force-pushed the 198-nft-metada-and-creation-time branch from 8d9e7d8 to e362dc8 Compare March 7, 2025 10:31
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
… docs (#198)

Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
… optional (#198) (#250)

Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
@arianejasuwienas arianejasuwienas force-pushed the 198-nft-metada-and-creation-time branch from e362dc8 to 5d88244 Compare March 7, 2025 15:13
@acuarica acuarica marked this pull request as draft March 7, 2025 21:31
@acuarica
Copy link
Copy Markdown
Contributor

acuarica commented Mar 7, 2025

@arianejasuwienas marked this as draft because moving forward we should also include validation tests.

@acuarica acuarica closed this Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Enhancing an existing feature driven by business requirements. Typically backwards compatible.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NFT metadata and creation time

2 participants