0
0
Blockchain / Solidityprogramming~10 mins

Deploying to L2 networks in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Deploying to L2 networks
Write Smart Contract
Compile Contract
Connect to L2 Network
Deploy Contract
Confirm Deployment
Interact with Contract on L2
This flow shows the steps to deploy a smart contract on a Layer 2 blockchain network, from writing code to interacting after deployment.
Execution Sample
Blockchain / Solidity
const contract = await ethers.getContractFactory("MyContract");
const deployed = await contract.deploy();
await deployed.deployed();
console.log("Deployed to L2 at", deployed.address);
This code deploys a smart contract to an L2 network and logs its address after deployment.
Execution Table
StepActionEvaluationResult
1Get contract factoryethers.getContractFactory("MyContract")Contract factory object ready
2Deploy contractcontract.deploy()Transaction sent to L2 network
3Wait for deploymentdeployed.deployed()Deployment confirmed on L2
4Log addressconsole.log(...)Prints deployed contract address
💡 Deployment confirmed and contract address logged, process complete
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
contractundefinedContract factory objectContract factory objectContract factory objectContract factory object
deployedundefinedundefinedDeployed contract instanceDeployed contract instanceDeployed contract instance
Key Moments - 2 Insights
Why do we wait for 'deployed.deployed()' before using the contract address?
Waiting for 'deployed.deployed()' ensures the contract is fully deployed on the L2 network before interacting, as shown in execution_table step 3.
What does 'ethers.getContractFactory' do in deployment?
'ethers.getContractFactory' prepares the contract code for deployment, creating a factory object as seen in execution_table step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of 'contract' after step 2?
AContract factory object
BDeployed contract instance
CDeployment transaction object
DUndefined
💡 Hint
Check the 'contract' variable in variable_tracker after step 2
At which step does the deployment get confirmed on the L2 network?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
See execution_table step 3 description
If we skip waiting for 'deployed.deployed()', what might happen?
AContract address will be undefined
BDeployment will fail immediately
CWe might interact with a contract not yet deployed
DNothing changes, safe to skip
💡 Hint
Refer to key_moments about waiting for deployment confirmation
Concept Snapshot
Deploying to L2 networks:
1. Write and compile your smart contract.
2. Connect to the L2 network using a provider.
3. Use contract factory to deploy.
4. Wait for deployment confirmation with deployed.deployed().
5. Interact with the contract using its L2 address.
Full Transcript
Deploying to Layer 2 networks involves writing your smart contract code, compiling it, and then connecting to the Layer 2 blockchain network. Using a contract factory, you deploy the contract by sending a transaction to the network. It is important to wait for the deployment to be confirmed on the network before interacting with the contract. This ensures the contract is fully available and avoids errors. After confirmation, you can use the contract address to call functions or send transactions on the L2 network.