Bird
Raised Fist0
Blockchain / Solidityprogramming~5 mins

Deploying to L2 networks in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is an L2 network in blockchain?
An L2 (Layer 2) network is a secondary framework built on top of a main blockchain (Layer 1) to improve scalability and reduce transaction costs by processing transactions off the main chain.
Click to reveal answer
beginner
Why deploy smart contracts on L2 networks?
Deploying on L2 reduces gas fees, increases transaction speed, and helps scale applications without congesting the main blockchain.
Click to reveal answer
intermediate
Name two popular L2 solutions.
Optimistic Rollups and zk-Rollups are two popular L2 solutions that bundle transactions off-chain and submit proofs to the main chain.
Click to reveal answer
intermediate
What is a key step before deploying a contract to an L2 network?
You must configure your deployment tools (like Hardhat or Truffle) to connect to the L2 network's RPC endpoint and set the correct chain ID.
Click to reveal answer
intermediate
How does bridging assets relate to deploying on L2?
Bridging moves assets from the main chain to the L2 network so users can interact with contracts there using those assets.
Click to reveal answer
What is the main benefit of deploying smart contracts on L2 networks?
AMore complex contract code
BIncreased block size on Layer 1
CLower transaction fees and faster processing
DEliminates need for Layer 1 blockchain
Which of the following is an example of an L2 scaling solution?
Azk-Rollups
BProof of Work
CSharding
DMining
Before deploying to an L2 network, you should:
AUse the same settings as Layer 1
BConfigure your deployment tool with the L2 network's RPC and chain ID
CDisable all Layer 1 nodes
DOnly write contracts in a new language
What does bridging do in the context of L2 networks?
ATransfers assets from Layer 1 to Layer 2
BCreates new tokens on Layer 1
CDeletes contracts on Layer 2
DIncreases gas fees
Which statement about L2 networks is true?
AThey increase transaction fees
BThey replace Layer 1 blockchains completely
CThey slow down transaction speed
DThey help scale blockchain by processing transactions off the main chain
Explain the process and benefits of deploying smart contracts to an L2 network.
Think about how L2 helps with blockchain scaling and what you need to change in deployment.
You got /3 concepts.
    Describe how bridging assets works and why it is important for interacting with L2 networks.
    Consider how users get their tokens onto the L2 network.
    You got /3 concepts.

      Practice

      (1/5)
      1. What is the main benefit of deploying smart contracts to Layer 2 (L2) networks?
      easy
      A. Increased decentralization over Layer 1
      B. More complex contract code execution
      C. Faster transactions and lower fees compared to Layer 1
      D. Unlimited storage capacity for contracts

      Solution

      1. Step 1: Understand Layer 2 purpose

        Layer 2 networks are designed to improve blockchain scalability by handling transactions off the main chain.
      2. Step 2: Identify benefits of L2

        This results in faster transaction speeds and lower fees compared to Layer 1.
      3. Final Answer:

        Faster transactions and lower fees compared to Layer 1 -> Option C
      4. Quick Check:

        L2 improves speed and cost [OK]
      Hint: L2 means faster and cheaper transactions than L1 [OK]
      Common Mistakes:
      • Confusing L2 with increased decentralization
      • Thinking L2 allows unlimited storage
      • Assuming L2 makes contracts more complex
      2. Which of the following is the correct syntax to specify an L2 network in a deployment script using Hardhat?
      easy
      A. "network: 'layer2'" inside the config file
      B. "network: 'l1'" inside the deployment script
      C. "network: 'mainnet'" inside the config file
      D. network: 'layer2'" without quotes in the script

      Solution

      1. Step 1: Recognize correct network naming

        In Hardhat config, network names are strings and must be quoted.
      2. Step 2: Identify L2 network syntax

        Using "network: 'layer2'" inside the config file is the correct way to specify the L2 network.
      3. Final Answer:

        "network: 'layer2'" inside the config file -> Option A
      4. Quick Check:

        Network names are strings in config [OK]
      Hint: Network names must be strings in config files [OK]
      Common Mistakes:
      • Using unquoted network names causing syntax errors
      • Confusing L1 and L2 network names
      • Placing network setting inside deployment script instead of config
      3. Given this deployment snippet for an L2 network:
      const network = 'layer2';
      console.log(`Deploying to ${network}`);
      
      What will be the output?
      medium
      A. Deploying to ${network}
      B. Deploying to layer2
      C. Deploying to network
      D. Error: network not defined

      Solution

      1. Step 1: Understand template literals

        The backticks and ${} syntax insert variable values into strings.
      2. Step 2: Substitute variable value

        Here, ${network} becomes 'layer2', so the output is 'Deploying to layer2'.
      3. Final Answer:

        Deploying to layer2 -> Option B
      4. Quick Check:

        Template literal inserts variable [OK]
      Hint: Backticks with ${} insert variables in strings [OK]
      Common Mistakes:
      • Confusing template literals with normal quotes
      • Expecting literal ${network} output
      • Assuming variable is undefined
      4. You try to deploy a contract to an L2 testnet but get an error: "Invalid RPC URL". What is the most likely cause?
      medium
      A. Your private key is invalid
      B. The contract code has syntax errors
      C. You forgot to compile the contract
      D. The RPC URL for the L2 network is missing or incorrect in the config

      Solution

      1. Step 1: Understand RPC URL role

        The RPC URL connects your deployment tool to the blockchain network.
      2. Step 2: Link error to cause

        An "Invalid RPC URL" error means the URL is missing or wrong in the config file.
      3. Final Answer:

        The RPC URL for the L2 network is missing or incorrect in the config -> Option D
      4. Quick Check:

        Invalid RPC URL means wrong/missing URL [OK]
      Hint: Check RPC URL correctness in config first [OK]
      Common Mistakes:
      • Assuming contract code errors cause RPC URL errors
      • Ignoring network config settings
      • Not verifying private key separately
      5. You want to deploy a contract to an L2 network but keep your private key secure. Which approach is best?
      hard
      A. Store the private key in environment variables and load it securely
      B. Use a public key instead of a private key for deployment
      C. Share the private key in the project README for easy access
      D. Hardcode the private key in the deployment script

      Solution

      1. Step 1: Understand private key security

        Private keys must be kept secret to prevent unauthorized access.
      2. Step 2: Identify secure storage method

        Using environment variables keeps keys out of code and version control, enhancing security.
      3. Final Answer:

        Store the private key in environment variables and load it securely -> Option A
      4. Quick Check:

        Env vars keep keys secret [OK]
      Hint: Never hardcode keys; use environment variables [OK]
      Common Mistakes:
      • Hardcoding keys in scripts
      • Sharing keys publicly
      • Confusing public and private keys