Challenge 20
Calldata vs memory
LowSolidity basics
Challenge
A function takes an array argument and later uses it in a storage-impacting way. Which data location is safer for unmodified external inputs?
Starter code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract DataLocationDemo {
uint256[] public values;
function addValues(uint256[] memory input) public {
for (uint256 i = 0; i < input.length; i++) {
values.push(input[i]);
}
}
}Show hint
External data that is not modified should usually be read from calldata when possible.