Complete the code to declare a simple Solidity contract named MyContract.
contract [1] {
// contract code
}The contract name must be a valid identifier. Here, MyContract is the correct name.
Complete the code to declare a public state variable of type uint named count.
contract Counter {
[1] public count;
}string for numeric values.bool which only holds true or false.The uint type is used for unsigned integers in Solidity, suitable for counting.
Fix the error in the function declaration to make it a public function that increments count.
contract Counter {
uint public count;
function increment() [1] {
count += 1;
}
}private or internal which restrict access.The function must be public to be called from outside the contract.
Fill both blanks to create a mapping from address to uint named balances and a function to update it.
contract Wallet {
mapping([1] => [2]) public balances;
function updateBalance(address user, uint amount) public {
balances[user] = amount;
}
}string as key or value in mapping incorrectly.bool which is not suitable for balances.A mapping in Solidity links keys to values. Here, addresses map to unsigned integers.
Fill all three blanks to create a function that returns the balance of a given address.
contract Wallet {
mapping(address => uint) public balances;
function getBalance([1] user) public view returns ([2]) {
return balances[[3]];
}
}bool.The function takes an address parameter named user and returns a uint balance.