0
0
Blockchain / Solidityprogramming~10 mins

Multi-chain deployment 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 a contract named "MultiChain".

Blockchain / Solidity
contract [1] {
    // contract code
}
Drag options to blanks, or click blank then click option'
ADeployChain
BMultiChain
CMultiChainDeploy
DChainMulti
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different contract name that does not match the deployment context.
2fill in blank
medium

Complete the code to define a function that returns the current chain ID.

Blockchain / Solidity
function getChainId() public view returns (uint256) {
    return [1];
}
Drag options to blanks, or click blank then click option'
Ablock.chainid
Bblock.number
Cmsg.sender
Dtx.origin
Attempts:
3 left
💡 Hint
Common Mistakes
Using block.number which returns the block height, not the chain ID.
Using msg.sender or tx.origin which relate to addresses, not chain info.
3fill in blank
hard

Fix the error in the function that sets the chain-specific address mapping.

Blockchain / Solidity
mapping(uint256 => address) public chainAddresses;

function setAddress(uint256 chainId, address addr) public {
    chainAddresses[[1]] = addr;
}
Drag options to blanks, or click blank then click option'
AchainId
BchainAddresses
Cmsg.sender
Daddr
Attempts:
3 left
💡 Hint
Common Mistakes
Using the address or the mapping itself as the key instead of the chain ID.
4fill in blank
hard

Fill both blanks to complete the function that returns the address for the current chain.

Blockchain / Solidity
function getAddress() public view returns (address) {
    uint256 currentChain = [1];
    return chainAddresses[[2]];
}
Drag options to blanks, or click blank then click option'
Ablock.chainid
Bmsg.sender
CcurrentChain
Dtx.origin
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.sender or tx.origin instead of the chain ID.
Using block.chainid directly in the return statement without storing it first.
5fill in blank
hard

Fill all three blanks to complete the multi-chain deployment contract with initialization.

Blockchain / Solidity
contract MultiChain {
    mapping(uint256 => address) public chainAddresses;

    constructor(address [1]) {
        uint256 chainId = [2];
        chainAddresses[chainId] = [3];
    }
}
Drag options to blanks, or click blank then click option'
AinitialAddress
Bblock.chainid
Dmsg.sender
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.sender instead of the passed address parameter.
Not using block.chainid to get the chain ID.
Mixing up variable names in the constructor.