0
0
Blockchain / Solidityprogramming~10 mins

Deploying to L2 networks 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 specify the Layer 2 network RPC URL.

Blockchain / Solidity
const provider = new ethers.providers.JsonRpcProvider('[1]');
Drag options to blanks, or click blank then click option'
Ahttps://polygon-mumbai.infura.io/v3/YOUR-PROJECT-ID
Bhttps://rinkeby.infura.io/v3/YOUR-PROJECT-ID
Chttps://localhost:8545
Dhttps://mainnet.infura.io/v3/YOUR-PROJECT-ID
Attempts:
3 left
💡 Hint
Common Mistakes
Using a mainnet RPC URL instead of an L2 testnet URL.
Using a local blockchain URL which is not an L2 network.
2fill in blank
medium

Complete the code to deploy a contract using the signer connected to the L2 network.

Blockchain / Solidity
const signer = new ethers.Wallet('0xYOUR_PRIVATE_KEY', provider);
const factory = new ethers.ContractFactory(abi, bytecode, [1]);
const contract = await factory.deploy();
Drag options to blanks, or click blank then click option'
Asigner
Bprovider
Cwallet
Dcontract
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the provider instead of the signer.
Passing an undefined wallet object.
3fill in blank
hard

Fix the error in the code to wait for the contract deployment transaction to be mined on the L2 network.

Blockchain / Solidity
const tx = contract.deployTransaction;
await tx.[1]();
Drag options to blanks, or click blank then click option'
Aconfirm
Bwait
Cmine
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' which sends a transaction but does not wait.
Using 'mine' or 'confirm' which are not valid methods.
4fill in blank
hard

Fill the blanks to create an object that maps contract names to their deployed addresses on the L2 network, filtering only those with addresses starting with '0x'.

Blockchain / Solidity
const deployedContracts = Object.keys(contracts).reduce((acc, [1]) => {
  if (contracts[[1]].address && contracts[[1]].address.[2]('0x')) {
    acc[[1]] = contracts[[1]].address;
  }
  return acc;
}, {});
Drag options to blanks, or click blank then click option'
Aname
BstartsWith
Cincludes
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'includes' instead of 'startsWith' which checks anywhere in the string.
Using 'address' as the loop variable which is incorrect.
5fill in blank
hard

Fill all three blanks to filter and map contract deployment info: create a new object with keys as uppercased contract names, values as addresses, only for contracts deployed on the L2 network with gas used greater than 100000.

Blockchain / Solidity
const filteredContracts = Object.entries(deployments).reduce((acc, [constName, info]) => {
  if (info.network === 'L2' && info.gasUsed [3] 100000) {
    acc[[1]] = [2];
  }
  return acc;
}, {});
Drag options to blanks, or click blank then click option'
AconstName.toUpperCase()
Binfo.address
C>
DconstName
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original contract name instead of uppercased.
Using '<' instead of '>' for gasUsed comparison.