I created a simple For loop that should return an array of numbers. But it fails with errored: VM error: revert
I guess there is something fundamental I am missing here, so I hope you guys can help here.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract ForLoop {
function getOwnedTokens() public pure returns (uint[] memory) {
uint[] memory listOfOwnedTokens;
uint numberOfOwnedTokens = 4;
for(uint tokenIndex = 0; tokenIndex < numberOfOwnedTokens; tokenIndex++) {
listOfOwnedTokens[tokenIndex] = tokenIndex;
}
return listOfOwnedTokens;
}
}