0
0
Blockchain / Solidityprogramming~10 mins

Upgrade strategies in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a new version number for a smart contract upgrade.

Blockchain / Solidity
uint256 public constant VERSION = [1];
Drag options to blanks, or click blank then click option'
Av1
B"1"
Cversion1
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for the version.
Using an undefined variable name.
2fill in blank
medium

Complete the code to emit an event when the contract is upgraded.

Blockchain / Solidity
event Upgraded(address indexed [1]);
Drag options to blanks, or click blank then click option'
Asender
Bowner
Cupgrader
Dcaller
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like owner which may not reflect the upgrader.
Using sender which is less descriptive here.
3fill in blank
hard

Fix the error in the upgrade function to correctly call the new implementation.

Blockchain / Solidity
function upgradeTo(address newImplementation) external [1] {
    require(newImplementation != address(0), "Invalid address");
    _implementation = newImplementation;
    emit Upgraded(msg.sender);
}
Drag options to blanks, or click blank then click option'
Apublic
BonlyOwner
Cexternal onlyOwner
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving the function public without access control.
Using private which prevents external calls.
4fill in blank
hard

Fill both blanks to create a mapping that stores upgrade timestamps and a function to check if upgrade is allowed.

Blockchain / Solidity
mapping(address => uint256) public [1];

function canUpgrade(address upgrader) public view returns (bool) {
    return block.timestamp >= [2][upgrader] + 1 days;
}
Drag options to blanks, or click blank then click option'
AlastUpgradeTime
BupgradeTimes
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the mapping and in the function.
Choosing unclear or inconsistent variable names.
5fill in blank
hard

Fill all three blanks to implement a function that upgrades the contract only if the new version is higher and updates the version number.

Blockchain / Solidity
function upgradeToVersion(uint256 newVersion, address newImplementation) external [1] {
    require(newVersion > [2], "Version must be higher");
    upgradeTo(newImplementation);
    [3] = newVersion;
}
Drag options to blanks, or click blank then click option'
AonlyOwner
BVERSION
CcurrentVersion
D_version
Attempts:
3 left
💡 Hint
Common Mistakes
Not restricting the function to the owner.
Comparing with the wrong version variable.
Not updating the version after upgrade.