Complete the code to define a simple Ethereum smart contract that stores a number.
contract SimpleStorage {
uint256 public [1];
}The variable storedData is a common name used to store data in simple contracts.
Complete the code to create a function that sets the stored number.
function set(uint256 x) public {
[1] = x;
}The function sets the value of the variable storedData to the input x.
Fix the error in the function to return the stored number correctly.
function get() public view returns (uint256) {
return [1];
}The function returns the value of storedData, which holds the stored number.
Fill both blanks to create a mapping that stores balances and a function to update it.
mapping(address => uint256) public [1]; function updateBalance(address user, uint256 amount) public { [2][user] = amount; }
The mapping balances stores the balance for each address, and the function updates it.
Fill all three blanks to create a function that transfers tokens between users.
function transfer(address to, uint256 amount) public {
require([1][msg.sender] >= amount, "Insufficient balance");
[2][msg.sender] -= amount;
[3][to] += amount;
}The function checks the sender's balance in balances, subtracts the amount, and adds it to the recipient's balance.