2

I am creating a token like this:

pragma solidity ^0.5.0;

import "../utils/math/SafeMath.sol";


contract ExampleDivisibleNFTs {
    using SafeMath for uint256;

    // Percentage of ownership over a token  
    mapping(address => mapping(string => uint)) ownerToTokenShare;

    // If a token has been created
    mapping(string => bool) mintedToken;

    modifier onlyNonExistentToken(string _tokenId) {
        require(mintedToken[_tokenId] == false, "the NFT already exists");
        _;
    }

    modifier onlyExistentToken(string _tokenId) {
        require(mintedToken[_tokenId] == true, "the NFT doesn't exists");
        _;
    }

}

and I am testing with remix but I have the following problem

Data location must be "storage" or "memory" for parameter in function, but none was given.

modifier onlyNonExistentToken(string _tokenId) {
                              ^-------------^

why a parameter may to be a "storage", It is not always "memory" ?

1

The solidity compiler requires an explicit declaration of the data location for persistency and semantic reasonings.

With that being said, in your particular smart contract, the _tokenID string is passed by reference and because of the fact that the reference --> points to your mintedToken mapping, then it’s a reference to storage which is why the compiler begs you to explicitly declare it as such.

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.