0
pragma solidity ^0.7.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/token/ERC721/ERC721.sol";

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/utils/Counters.sol";

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/access/Ownable.sol";

contract DigitalIdentity is ERC721, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;
    string private _fullname;
    uint256 private _age;

    constructor() ERC721("Digital-Identity", "DID") {}

    function uint2str(uint256 _i) 
    internal pure returns (string memory str) {
        if (_i == 0)
        {
            return "0";
        }
        uint256 j = _i;
        uint256 length;
        while (j != 0)
        {
            length++;
            j /= 10;
        }
        bytes memory bstr = new bytes(length);
        uint256 k = length;
        j = _i;
        while (j != 0)
        {
            bstr[--k] = bytes1(uint8(48 + j % 10));
            j /= 10;
        }
        str = string(bstr);
    }

    function append(string memory a, string memory b, string memory c, 
    string memory d, string memory e) internal pure returns 
    (string memory) {

        return string(abi.encodePacked(a, b, c, d, e));
    }

    function readId() external view returns(string memory) {
        // anyone can call this readId()
        string memory idstring = append(uint2str(_tokenIds.current()),"_",
        _fullname,"_", uint2str(_age));
        return idstring;
    }
    
    function generateNft(address receiver, string memory tokenURI, 
                         string memory fullname, uint256 age) 
                         external onlyOwner returns (uint256) {
        _tokenIds.increment();

        uint256 newNftTokenId = _tokenIds.current();
        _mint(receiver, newNftTokenId);
        _setTokenURI(newNftTokenId, tokenURI);
        _fullname = fullname;
        _age = age;

        return newNftTokenId;
    }
}
1
  • 1
    Which network did you use mainnet, ropsten, rinkeby? What's the compiler version? What were the compilation parameters? optimizacion, number of runs. What's the contract address? What did you try? and what didn't work?
    – Ismael
    Mar 24, 2021 at 23:30

1 Answer 1

0

Your first problem is in line 1, ^.

This doesn't really disambiguate while compiler was actually used so you need to know that or have to try to them all. Normally, you still need to know about compiler optimization runs but the search area is smaller.

Source code verification works by compiling the code you provide, with the parameters you specify and then comparing the output to the code on the chain. If it matches to the last byte then the code will be accepted. So, as a general habit, I would discourage using ranges in a top-level contract.

The second problem is these lines:

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/token/ERC721/ERC721.sol";

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/utils/Counters.sol";

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4/contracts/access/Ownable.sol";

These lines suggest fetching code from another source. I'm not sure how Etherscan deals with it at this time because I would never use that feature. It makes it very difficult to conclusively determine that the entirety of the code is an accurate representation of what was compiled and deployed.

I wish I had better news, but you have to resolve both problems and then tell it which compiler was actually used (possibly you can get an indication from your IDE) and work out if it was optimized and if so, how may cycles? When you have the right code and compile it the same way, then it will work.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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