Complete the code to declare a mapping in Solidity that links addresses to balances.
mapping(address => uint) public [1];The mapping name balances is commonly used to store user balances in Solidity smart contracts.
Complete the code to add a new element to a dynamic array in Solidity.
uint[] public numbers;
function addNumber(uint num) public {
numbers.[1](num);
}The push function adds a new element to the end of a dynamic array in Solidity.
Fix the error in the code to correctly check if a key exists in a mapping.
mapping(address => uint) public balances;
function hasBalance(address user) public view returns (bool) {
return balances[[1]] != 0;
}msg.sender which checks the caller, not the input address.address which is a type, not a variable.The function parameter user should be used to check the balance in the mapping.
Fill both blanks to create a struct and declare a mapping from address to that struct.
struct [1] { uint balance; uint lastUpdated; } mapping(address => [2]) public accounts;
The struct is named Account and the mapping uses the same struct type.
Fill all three blanks to create a mapping with a nested mapping for token balances.
mapping(address => mapping([1] => uint)) public [2]; function getBalance(address user, [3] token) public view returns (uint) { return [2][user][token]; }
The nested mapping uses address as the key type for tokens, the mapping is named balances, and the function parameter for token is an address.