How To Deploy Smart Contracts on Linea Blockchain
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8383ee93ebe3711046e0_KpFWBM5lw-EYl36zrgzoA-zF20B0f2ctxJL7uP5wbtUHGNyWvVHo-CJ5H9ntp3nIltOnJLpd14AMsx-qzgjh8M8QIE2oAw-fz8Xs9i1PuOmTGmbx9VV9YZU8gMp-cr_40MRn8zxspZJvfEXpGP5z21I.png)
Linea is an EVM-compatible Layer-2 scaling solution for Ethereum. Linea aims to provide users with a faster and cheaper way to transact while enjoying the security of the underlying layer-1 network by vertically scaling Ethereum. Linea uses Zero Knowledge Proofs (zkProofs) and offline computation techniques to achieve high throughput and offload the traffic from the parent layer-1 blockchain, Ethereum.
Linea is type 1 zkEVM, which means it is EVM equivalent and does not require changing any part of the system, making it perfectly compatible with Ethereum, which allows developers to use a lot of existing infrastructure.
Learn more about Linea zkEVM blockchain.
Linea's out-of-the-box compatibility with the Ethereum Virtual Machine enables an easy porting and deployment of pre-existing smart contracts and dapps and the creation of new ones that would otherwise be costly on Mainnet.
Let’s jump into smart contract deployment on Linea —
Getting Started
Before we dive into the deployment process, you need a few prerequisites to have in place:
- Wallet: To deploy a smart contract, you need a Web3 wallet. For this tutorial, we will be using the Metamask browser wallet. You can download Metamask from here.
- Wallet Funds: To need to pay a gas fee to deploy contracts to the blockchain. You need to fund your wallet with ETH to cover those gas fees for contract deployment. You can follow this guide to bridge funds to the Linea blockchain.
- For this tutorial, we will be deploying contracts to the Linea blockchain using Hardhat. Use these resources to set up your environment according to Hardhat's recommended instructions.
Create A Hardhat project
Create an empty Hardhat project by running the following commands:
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8382b59f5bc545eb395d_dCUBvimXP4KEQEoQT6hDzZn6aTpy-xPQCl2ux_TVyX-MxQD9J3zILvekkf66rYCPI9Si3Zlrc4_d6sKrM35iLD7t0X2ijjIPk1BxnHNjYI2vLPtyvUr3jda76Q_3840kvuBN5EqvYUoCI7YAl-s8NZQ.png)
Select Create an empty hardhat.config.js in the next menu and hit Enter.
Hardhat recommends installing the @nomicfoundation/hardhat-toolbox plugin. You can download the plugin by entering Y during the project creation process.
Alternatively, you can run the following command in your project directory to install @nomicfoundation/hardhat-toolbox plugin —
You should now have a sample project from Hardhat that deploys and tests a Lock contract which locks funds for a set amount of time.
Note: Upon deployment, 0.001 ETH is automatically locked in the contract by the default script in scripts/deploy.js. If you want to avoid this, modify const lockedAmount = hre.ethers.parseEther("0.001"); to const lockedAmount = 0;.
Deploy The Contract
The above sample project already includes the deployment script. You just need to make a few modifications to deploy on Linea zkEVM.
To directly deploy the contract with your MetaMask wallet, use Truffle Dashboard. Otherwise, you can deploy with the Hardhat CLI by adding Linea to your hardhat.config.js.
Deploying the contract using Truffle Dashboard
The main advantage of using Truffle Dashboard is that it allows you to avoid saving your private keys locally and instead, you can use MetaMask wallet for deployments.
To deploy with Truffle Dashboard, download the Truffle-Hardhat integration plugin.
To configure:
1. Install Truffle by following this guide.
2. Run following command
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8382e3f0649a05910201_Oy-7QbXNbq7a2_AFLyPvi659rdbf7ku0zatgEAKXDnav8myaGk20IlCWTlH7iDyZEpddBh8QhoQYNp4oa6ThNzRh01C8I1DEmZUdqLzt1ZS6V6Bju7_XFwf2dhJHTYB4lpkQN8-cEndSRlfaDtlpG2E.png)
3. Import the plugin into hardhat.config.js by running
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8382f112480bc5962c65_9HxnPPuGGZfaKLppv4xr8EH-n9zErDWpN1qDOgvGNH_zzuXLT32t0NQq7QkzEIbEdxVxOWVgA--llqCNuBwSB3PlKXihxmS34EdqgJQ6Gw3F-y3rlBZoWanOBDC57xtF7JmJewGZa-2vEcEoVOiczU4.png)
Or
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8382cb0eb1e48c461810_buqEfxkZWTsGVfPQiksD-drndNqliLBeT0VKuJtgzC6G93BUd9ceyVOndO5tzh4yaCa0cAosKDBWEQm4tixc53fU7jIJOd7SyiPg_cB3TmEGPlnFGavOPBTeCNFsJakLEGMRx3ZLAL5n6qiACo0KAFw.png)
4. Run the Truffle Dashboard in your terminal, which should open a window on port 24012. Next, navigate to localhost:24012 in your browser.
Ensure that the Truffle Dashboard is connected to the Linea mainnet by adding Linea to your MetaMask wallet.
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8382c3b6732ca1c3c5a5_XObTZ51FwR2ItOSNrIV_o48pwTWBvEDKt8lo8zwsytJa_Dgn0acHhaF9EQ5s4fygo7wzEasTmJOvTPOSkIHtwbcRj52C5LG9L1gYEYxA6AKutqv18tWe2HyLSUbSILlmRGuGErt0hHGxN-Ang-xnCJs.png)
5. Run the following command in your Hardhat project using a separate terminal
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8383f112480bc5962d38_dMuKyMLUEbZ22qwQKDiHbqZkjPNAvY_XJNGR8RPHLi8t6_RKQ_72B_t5Me9KzGJjudZzsujKIrELeSrtQYw5kK04u4rTkBQQG95UMnEi74J857oURpTtd96c1hnJR5ir2uY-MXZcAhOZb5uy0VY4x-s.png)
6. Navigate back to localhost:24012. Confirm the deployment by clicking Confirm in the prompt on your screen.
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8383cb0eb1e48c4618a4_3PmQG0u6STmT1MyWjo6muNeQgL_YqGOxz8ISxCEmwYad-_ICpcOuVyphfrzDEmj69jIcWD5Ki3KhK2O96Aqe72XQlPySeBXDSveycIZTRCS17BPcAMFJE_V5qzsTiUFhUq534xguzxLNnVjy4EEirt0.png)
7. Once confirmed, you should see something similar to the following
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8383815fa76070bc314b_hboE3B9yoVcSnR4HNL8PA8K4NdpbIvm-GoPCz2yoQIz1z06rkYJYLB7BoEWG7nhmE5lTSlU42OV1opz5y4WoOVJ19GI4bDSq84wRtTioz3VBhFQHANSSUyhyANKQ6zfwMXQYWpuzJYrhv3TijazKNF8.png)
Deploying the contract using hardhat.config.js
To deploy to Linea zkEVM, add the network to hardhat.config.js by following these instructions:
1. Create a .env file in the root folder with your wallet's private key by running:
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee838345b217c3c3683985_Mp9X1072zb9Uu4dNfcid59x3Akd9uMvMeLhmWOZFvu-rKX5TkAwEl3S64BGFUJKM3PS00c2Sr8BSgJ76c7Y5zfFfQcXp7bvjhTlNkpAUG9mlQWaav19fwjLNWuc8jZL65-IMIfZcA9PDvMH_Fbrec3w.png)
2. Download dotenv
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8383556ad1f107612aa9_CkXfld_y2_AIeMk0phG_JlJPqjmFivPnqeY4tWW-_Y_Y0u4_l9H6F5-s4U0c5LEMfZ_MBJONXII3m2282h8dn_SAqeTh3btpgR1pO-d63oGfAm1OuQ4uQYs2wLp9DX3WLnPa1-YT2O7Z517_14pMU8Y.png)
3. Add Linea to your hardhat.config.js file by entering your Infura API Key, run:
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8383bbfb013ab5b634c5_WZbW143_7NtWnY9kWKeq7m6qratk9lepxyD1bn56cXe0oZPglXoV8lxcaZKEMDNhHb_zQ8UoXRBZgjRgvG-ZSVPmMaU_yDO3ZmfJ3ANbEax6V2kb4maDoHzN40gw5HfeyYsUxNBiJHUYGSi4sS2LWMI.png)
Get an Infura API Key from here.
Next, modify hardhat.config.js as follows:
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee83834bb9724aace3dc10_Q3_MapnJyrVCVtG1ap11FoWYME7JRGhECS2JpYQieBNAp3tuTRwGpIcQEpCTouPk8S-4YZksUUQ9tGMUdRkz059-MHYD5jr2mR6wOS_mZ3Ve5YH5gTI_HuN6WT1UAU7e21s9gdYn1jiuemZny9V6nKo.png)
4. Call npx hardhat run scripts/deploy.js --network linea_mainnet from the CLI.
You should get an output something like this:
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee838364478838cfda90b3_ef0WENdJia7-zFoPshrZfLx8v5r-n6c_LGtGIjwSJVo_fIj-jTmHf8Ti7b5j9CM7qItt5TNBAsjGIm1Ux9v0hv_IujDE2KMGEfdnRN4NaHhcr8HxFY5F7cVKRD6jc-J4O_pwHUI0EoNTrWJjKTrUbEo.png)
Verifying The Deployed Smart Contract
1. Add the @nomicfoundation/hardhat-toolbox or @nomicfoundation/hardhat-verify plugin to your project
2. Get and add your Lineascan API Key to your hardhat.config.js.
3. Add the custom Linea chain to your hardhat.config.js.
Note: The Etherscan apiKey and network name for your custom chain must be the same as under networks in your hardhat.config.js.
4. Finally, to verify your contract, run the following command:
npx hardhat verify --network linea_mainnet <DEPLOYED_CONTRACT_ADDRESS> <CONTRACT_ARGUMENTS>
After a successful verification, you should see something similar to the following
![](https://cdn.prod.website-files.com/62cd593e955c2638cf28f54d/64ee8384c962bdbc5d6fbe9a_RaxRbj33KCquMfFpEltGQEQjYtAQ5GY9lyby8ujwMWOO6ULZNClUQppzzqhk1Trs3ktZvTNFPY_etiNRumyWChZgT3iezdimOe0cuCKHWXw5mU-A_LiKIIFGBwjx660Ok3fIgFMokIij8ON5PuQ6adY.png)
You can check if your contract was verified correctly by navigating to the Linea mainnet block explorer and pasting in the deployed contract address.
By following this guide, you should be able to understand how to deploy and verify the smart contracts on the Linea zkEVM blockchain.
Looking To Build On Linea?
If you want to build a project on the Linea blockchain, and looking for development services — Schedule a free consultation with our team today, or email us to discuss your project.