0

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];
}
saeedhsb
  • 3
  • 2
  • hello you have declared mapping as tokenToURI. So, you need return as the same name like tokenToURI[tokenType]. try this – Chetan Ukani Aug 05 '22 at 08:59

2 Answers2

0

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];
}
saeedhsb
  • 3
  • 2
0

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

Dean97K
  • 60
  • 5