Error while returning a string from a function

160 Views Asked by At

I'm trying to make a function that returns string from mapping(uint256 => string) typeToURI; but I keep getting an error from Remix Ethereum IDE:

TypeError: Return argument type uint256[] storage ref is not implicitly convertible to expected type (type of first return variable) string memory. --> NFT Minter.sol:88:16: | 88 | return typeToToken[tokenType]; | ^^^^^^^^^^^^^^^^^^^^^^

I know I should use the memory type somewhere to fix this issue but I don't know where.

I have tried putting memory type in mapping : mapping(uint256 => memory string) typeToURI; but it didn't worked and it causes another error.

source code:

mapping(uint256 => string) tokenToURI;


function tokenTypeURI(uint256 tokenType) public
    returns (string memory)
{
    return typeToToken[tokenType];
}
2

There are 2 best solutions below

0
saeedhsb On BEST ANSWER

Actually it was a missundrestanding that instead of typeToURI I used another mapping typeToToken.

So there is no need to do any conversations between string memory and memory.

the code for refrence:

mapping(uint256 => string) tokenToURI;

function tokenTypeURI(uint256 tokenType) public
    returns (string memory)
{
    return typeToToken[tokenType];
}
0
Dean97K On

you are accessing wrong variable. fix typeToToken[tokenType] to tokenToURI[tokenType]