0
0
Blockchain / Solidityprogramming~10 mins

Diamond pattern (EIP-2535) 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 the DiamondCutFacet contract.

Blockchain / Solidity
contract DiamondCutFacet is IDiamondCut {
    function diamondCut(
        IDiamondCut.FacetCut[] memory _diamondCut,
        address _init,
        bytes memory _calldata
    ) external override [1] {
        // Implementation
    }
}
Drag options to blanks, or click blank then click option'
Apure
Bpublic
Cexternal
Dinternal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'public' instead of 'external' causes mismatch with interface.
Using 'internal' or 'private' makes the function inaccessible externally.
2fill in blank
medium

Complete the code to add a facet address to the diamond storage.

Blockchain / Solidity
library LibDiamond {
    struct FacetAddressAndSelectorPosition {
        address facetAddress;
        uint16 selectorPosition;
    }

    struct DiamondStorage {
        mapping(bytes4 => FacetAddressAndSelectorPosition) selectorToFacetAndPosition;
        address[] facetAddresses;
    }

    function diamondStorage() internal pure returns (DiamondStorage storage ds) {
        bytes32 position = keccak256("diamond.standard.diamond.storage");
        assembly {
            ds.slot := position
        }
    }

    function addFacetAddress(address _facetAddress) internal {
        DiamondStorage storage ds = diamondStorage();
        ds.facetAddresses.[1](_facetAddress);
    }
}
Drag options to blanks, or click blank then click option'
Apush
Bappend
Cadd
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' which is not a Solidity array method.
Using 'add' or 'insert' which do not exist for arrays.
3fill in blank
hard

Fix the error in the diamondCut function signature to match the interface.

Blockchain / Solidity
function diamondCut(
    IDiamondCut.FacetCut[] memory _diamondCut,
    address _init,
    bytes memory _calldata
) external override [1] {
    // Implementation
}
Drag options to blanks, or click blank then click option'
Apure
Bpayable
Cview
Dnonpayable
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting 'payable' causes the function to reject Ether transfers.
Using 'pure' or 'view' is incorrect because the function modifies state.
4fill in blank
hard

Fill both blanks to complete the diamondCut function call and event emission.

Blockchain / Solidity
function diamondCut(
    IDiamondCut.FacetCut[] memory _diamondCut,
    address _init,
    bytes memory _calldata
) external override payable {
    LibDiamond.diamondCut(_diamondCut, _init, _calldata);
    emit [1](_diamondCut, _init, _calldata);
}

// Event declaration
event [2](IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata);
Drag options to blanks, or click blank then click option'
ADiamondCut
BCutDiamond
CDiamondUpdate
DCutEvent
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect event names causes compilation or runtime errors.
Mismatch between event declaration and emission.
5fill in blank
hard

Fill all three blanks to complete the diamondCut function call with correct parameters and event emission.

Blockchain / Solidity
function diamondCut(
    IDiamondCut.FacetCut[] memory [1],
    address [2],
    bytes memory [3]
) external override payable {
    LibDiamond.diamondCut([1], [2], [3]);
    emit DiamondCut([1], [2], [3]);
}
Drag options to blanks, or click blank then click option'
A_diamondCut
B_init
C_calldata
D_data
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names causes errors.
Using '_data' instead of '_calldata' is incorrect.