Complete the code to declare a contract named "MultiChain".
contract [1] {
// contract code
}The contract name must match the intended name for clarity and deployment. "MultiChain" is the correct name here.
Complete the code to define a function that returns the current chain ID.
function getChainId() public view returns (uint256) {
return [1];
}block.number which returns the block height, not the chain ID.msg.sender or tx.origin which relate to addresses, not chain info.The block.chainid returns the current blockchain's chain ID, which is essential for multi-chain deployment.
Fix the error in the function that sets the chain-specific address mapping.
mapping(uint256 => address) public chainAddresses;
function setAddress(uint256 chainId, address addr) public {
chainAddresses[[1]] = addr;
}The mapping key should be the chainId parameter to correctly store the address for that chain.
Fill both blanks to complete the function that returns the address for the current chain.
function getAddress() public view returns (address) {
uint256 currentChain = [1];
return chainAddresses[[2]];
}msg.sender or tx.origin instead of the chain ID.block.chainid directly in the return statement without storing it first.The function first gets the current chain ID using block.chainid and then returns the address stored for that chain using the variable currentChain.
Fill all three blanks to complete the multi-chain deployment contract with initialization.
contract MultiChain {
mapping(uint256 => address) public chainAddresses;
constructor(address [1]) {
uint256 chainId = [2];
chainAddresses[chainId] = [3];
}
}msg.sender instead of the passed address parameter.block.chainid to get the chain ID.The constructor takes an initialAddress parameter, gets the current chain ID with block.chainid, and sets the mapping for that chain to the initial address.