Challenge - 5 Problems
SPDX and Pragma Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this SPDX license and pragma version check?
Consider this Solidity code snippet:
What will the function
pragma solidity ^0.8.0;
// SPDX-License-Identifier: MIT
contract Test {
function version() public pure returns (string memory) {
return "^0.8.0";
}
}What will the function
version() return when called?Blockchain / Solidity
pragma solidity ^0.8.0; // SPDX-License-Identifier: MIT contract Test { function version() public pure returns (string memory) { return "^0.8.0"; } }
Attempts:
2 left
💡 Hint
Look at what the function returns as a string literal.
✗ Incorrect
The function returns the string "^0.8.0" exactly as coded. SPDX license comment is ignored at runtime.
❓ Predict Output
intermediate2:00remaining
What error occurs with mismatched pragma version?
Given this Solidity code:
If you try to compile this code with Solidity compiler version 0.8.10, what will happen?
pragma solidity ^0.7.0;
// SPDX-License-Identifier: GPL-3.0
contract Sample {
uint public x = 10;
}If you try to compile this code with Solidity compiler version 0.8.10, what will happen?
Blockchain / Solidity
pragma solidity ^0.7.0; // SPDX-License-Identifier: GPL-3.0 contract Sample { uint public x = 10; }
Attempts:
2 left
💡 Hint
Check if the compiler version matches the pragma version range.
✗ Incorrect
The pragma ^0.7.0 means compiler versions 0.7.x only. Using 0.8.10 causes a compilation error due to version mismatch.
🔧 Debug
advanced2:00remaining
Identify the error caused by missing SPDX license identifier
Examine this Solidity code:
What issue will the Solidity compiler report when compiling this code?
pragma solidity ^0.8.0;
contract MissingSPDX {
uint public value = 5;
}What issue will the Solidity compiler report when compiling this code?
Blockchain / Solidity
pragma solidity ^0.8.0; contract MissingSPDX { uint public value = 5; }
Attempts:
2 left
💡 Hint
SPDX license identifier is a comment at the top of the file.
✗ Incorrect
Solidity compiler issues a warning if SPDX license identifier comment is missing but still compiles the code.
❓ Predict Output
advanced2:00remaining
What is the effect of multiple SPDX license identifiers in one file?
Consider this Solidity code:
What will the Solidity compiler do when compiling this file?
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract MultiSPDX {
uint public data = 42;
}What will the Solidity compiler do when compiling this file?
Blockchain / Solidity
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; contract MultiSPDX { uint public data = 42; }
Attempts:
2 left
💡 Hint
SPDX license identifier should appear only once per file.
✗ Incorrect
Solidity compiler throws an error if multiple SPDX license identifiers are present in the same file.
❓ Predict Output
expert2:00remaining
What is the output of this pragma version range check?
Given this Solidity code snippet:
If compiled with Solidity version 0.9.1, what will happen?
pragma solidity >=0.6.0 <0.9.0;
// SPDX-License-Identifier: Apache-2.0
contract VersionCheck {
function checkVersion() public pure returns (string memory) {
return "Version supported";
}
}If compiled with Solidity version 0.9.1, what will happen?
Blockchain / Solidity
pragma solidity >=0.6.0 <0.9.0; // SPDX-License-Identifier: Apache-2.0 contract VersionCheck { function checkVersion() public pure returns (string memory) { return "Version supported"; } }
Attempts:
2 left
💡 Hint
Check if 0.9.1 fits in the version range >=0.6.0 and <0.9.0.
✗ Incorrect
The pragma restricts compiler versions to less than 0.9.0, so 0.9.1 is outside the allowed range causing compilation failure.