0
0
Blockchain / Solidityprogramming~10 mins

Visibility modifiers (public, private, internal, external) 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 make the function accessible from anywhere.

Blockchain / Solidity
function greet() [1] returns (string memory) {
    return "Hello!";
}
Drag options to blanks, or click blank then click option'
Aprivate
Bpublic
Cinternal
Dexternal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'private' makes the function inaccessible from outside the contract.
Using 'internal' restricts access to the contract and its children only.
2fill in blank
medium

Complete the code to make the variable accessible only within the contract and derived contracts.

Blockchain / Solidity
uint256 [1] myNumber;
Drag options to blanks, or click blank then click option'
Ainternal
Bprivate
Cpublic
Dexternal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'public' exposes the variable to everyone.
Using 'private' restricts access only to the contract itself.
3fill in blank
hard

Fix the error in the function declaration to allow it to be called only from outside the contract.

Blockchain / Solidity
function externalCall() [1] {
    // function logic
}
Drag options to blanks, or click blank then click option'
Aexternal
Bprivate
Cpublic
Dinternal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'public' allows both internal and external calls.
Using 'private' restricts calls to inside the contract only.
4fill in blank
hard

Fill both blanks to create a private variable and a public function to access it.

Blockchain / Solidity
uint256 [1] secretNumber;
function getSecret() [2] view returns (uint256) {
    return secretNumber;
}
Drag options to blanks, or click blank then click option'
Aprivate
Bpublic
Cinternal
Dexternal
Attempts:
3 left
💡 Hint
Common Mistakes
Making the variable public exposes it directly.
Making the function private or internal hides it from external callers.
5fill in blank
hard

Fill all three blanks to define an internal variable, a private function, and a public function that calls the private one.

Blockchain / Solidity
uint256 [1] data;


function calculate() [2] view returns (uint256) {
    return data * 2;
}


function getResult() [3] view returns (uint256) {
    return calculate();
}
Drag options to blanks, or click blank then click option'
Ainternal
Bprivate
Cpublic
Dexternal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'public' for the private function exposes it.
Using 'private' for the public function hides it from outside.