Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a reusable contract template.
Blockchain / Solidity
contract [1] {
// common functions here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using specific contract names instead of a generic template.
✗ Incorrect
Using a generic name like Template helps create reusable contract patterns.
2fill in blank
mediumComplete the code to implement a singleton pattern in a smart contract.
Blockchain / Solidity
contract Singleton {
address private staticInstance;
function getInstance() public view returns (address) {
return [1];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the caller's address instead of the stored instance.
✗ Incorrect
The singleton pattern returns the single stored instance address.
3fill in blank
hardFix the error in the code to properly use the factory pattern for contract creation.
Blockchain / Solidity
contract Factory {
function create() public returns (address) {
[1] newContract = new [1]();
return address(newContract);
}
}
contract Product {} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the factory contract name as the new contract type.
✗ Incorrect
The factory creates new Product contracts, so the type must be Product.
4fill in blank
hardFill both blanks to implement an observer pattern in Solidity.
Blockchain / Solidity
contract Subject {
address[] public observers;
function [1](address observer) public {
observers.[2](observer);
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function or array method names.
✗ Incorrect
The function to add observers is commonly named registerObserver, and push adds to the array.
5fill in blank
hardFill all three blanks to complete a decorator pattern example in Solidity.
Blockchain / Solidity
contract Base {
function getValue() public pure virtual returns (uint) {
return [1];
}
}
contract Decorator is Base {
Base base;
constructor(Base _base) {
base = _base;
}
function getValue() public view override returns (uint) {
return base.getValue() [2] [3];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of addition.
Returning wrong base value.
✗ Incorrect
The base returns 10, and the decorator adds 5 using the plus operator.