0
0
Blockchain / Solidityprogramming~20 mins

SPDX license and pragma version in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SPDX and Pragma Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this SPDX license and pragma version check?
Consider this Solidity code snippet:
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";
    }
}
AMIT
B0.8.0
Cpragma solidity
D"^0.8.0"
Attempts:
2 left
💡 Hint
Look at what the function returns as a string literal.
Predict Output
intermediate
2:00remaining
What error occurs with mismatched pragma version?
Given this Solidity code:
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;
}
ARuntime error: invalid SPDX license
BCompiles successfully
CCompilation error: pragma version mismatch
DWarning: SPDX license missing
Attempts:
2 left
💡 Hint
Check if the compiler version matches the pragma version range.
🔧 Debug
advanced
2:00remaining
Identify the error caused by missing SPDX license identifier
Examine this Solidity 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;
}
AWarning: SPDX license identifier not provided
BError: Missing pragma version
CError: Contract name missing
DNo issues, compiles cleanly
Attempts:
2 left
💡 Hint
SPDX license identifier is a comment at the top of the file.
Predict Output
advanced
2:00remaining
What is the effect of multiple SPDX license identifiers in one file?
Consider this Solidity code:
// 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;
}
AError: Multiple SPDX license identifiers found
BWarning: Multiple SPDX license identifiers, using the first one
CCompiles successfully using the last SPDX license
DIgnores SPDX license comments and compiles
Attempts:
2 left
💡 Hint
SPDX license identifier should appear only once per file.
Predict Output
expert
2:00remaining
What is the output of this pragma version range check?
Given this Solidity code snippet:
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";
    }
}
ACompiles and returns "Version supported"
BCompilation error: pragma version not satisfied
CRuntime error: version mismatch
DWarning: SPDX license deprecated
Attempts:
2 left
💡 Hint
Check if 0.9.1 fits in the version range >=0.6.0 and <0.9.0.