3

I'm working with NEAR's canonical example of an NFT smart contract, which implements the NEP4 standard API for NFT tokens.

Half of those API calls require a 64-bit integer for the token_id argument.

I'd like to call this API from a web app. But those u64 values can't be normal Javascript numbers on the client side, because Javascript integers are only 53 bits wide

This workaround can work for some cases, but it requires changing the API signature. I think that breaks compatibility with the standard.

I've tried passing the value as a string, and as a BigInt. But I got errors in both cases.

How can I call NEAR contract methods from Javascript if they require 64-bit values? For instance, can I trick the JSON serializer to turn a BigInt on the client into a u64 on the wire?

Mykle Hansen
  • 552
  • 3
  • 11
  • Yes, as noted by Matt Lockyear: this was a question about the old, deprecated standard. NEP-171 solved this problem. Use that. – Mykle Hansen Mar 18 '22 at 22:04

2 Answers2

2

You are right this is a bug and should be fixed by fixing the signature to accept TokenId as a String and then parse it into u64. I filed an issue: https://github.com/near-examples/NFT/issues/117

2

This is the latest NFT standard. The one you are referencing is deprecated. Apologies for not answering the question, but I think it's important to point this out.

https://nomicon.io/Standards/NonFungibleToken/README.html

Reference implementation here: https://github.com/near/near-sdk-rs/tree/standards/nft/near-contract-standards/src/non_fungible_token

You can see another implementation of this standard here along with a marketplace here: https://github.com/near-apps/nft-market

mattdlockyer
  • 6,984
  • 4
  • 40
  • 44