1

MyERC721:

pragma solidity ^0.5.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol";

contract MyERC721 is ERC721Full, ERC721Mintable, Ownable {

    constructor() ERC721Full("ThuleenCert721", "TC721") public {}

    /**
    * Custom function to create a unique token
    * @param _to The address that will receive the minted tokens.
    * @param _tokenId The token id to mint.
    * @param _tokenURI The token URI of the minted token.    
    */
    function mintUniqueTokenTo (
    address _to,
    uint256 _tokenId,               
    string  memory _tokenURI // Store, receipient's name, grade and program details
    ) public
    {        
        super.mint(_to, _tokenId);        
        super._setTokenURI(_tokenId, _tokenURI);
    }
}

MyDeployment script using web3 (version0.2)

var tx = await nft.mintUniqueTokenTo(
            receipientAddress,
            122164239941406260, // <- tokenId
            tokenURI, { from: coinbase }
        );

The script above works is tokenId is smaller, say "12216" but with the value of "122164239941406260" (18 digits) the script gave me the following error:

UnhandledPromiseRejectionWarning: Error: invalid number value (arg="_tokenId", coderType="uint256", value=122164239941406260)

In fact, I tested with different (tokenId) values and it works up to 16 digits.

So I "assumed" the error "invalid number value" means the value is too large? Really? How do I solve this?

1

In web3 v0.20 there's a utility function that will convert its parameter to BigNumber.

For example in your case :

const myTokenId = web3.toBigNumber('122164239941406260');

var tx = await nft.mintUniqueTokenTo(
    receipientAddress,
    myTokenId, // <- tokenId
    tokenURI, { from: coinbase }
);
| improve this answer | |
0

In the JavaScript code you should manage data from uint256 as BigNumbers.

Elsewhere JavaScript cannot handle your data properly because there is not a native matching type in JavaScript.

Make just some research on the matter, you should be able to solve easily.

There are many examples here to, on this forum, just search for BigNumbers tag or search term.

| improve this answer | |
0

Thanks Rick,

Followed your advise and then I used Bignumber.js library and below is how I did it:

var tokenId = new BigNumber("UA900021343", 35) // where "UA900021343" is the value I need to convert to numbers only so that it is acceptable to MyERC721 contract.

var tx = await nft.mintUniqueTokenTo(
        receipientAddress,  // receipient's address
        tokenId.toString(), // <- tokenId
        tokenURI, { from: coinbase }
    );

 // where nft is the instance of MyERC721 contract.

It works for me but I'm not sure if it is the "correct" way. Hope this help anyone who stumbled across the same issue.

| improve this answer | |
0

using bignumber.toFixed is a better method.

| improve this answer | |
0

Pass large number as string adding single or double quotes that fixes the issue

var tx = await nft.mintUniqueTokenTo(
        receipientAddress,
        '122164239941406260', // <- tokenId
        tokenURI, { from: coinbase }
    );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.