How to Deploy A Smart Contract on Linea
This guide covers adding the network to a browser wallet, then deploying a simple contract using Foundry and Hardhat — pick whichever you prefer on Linea.
Last updated
Was this helpful?
Was this helpful?
curl -L https://foundry.paradigm.xyz | bash
foundryupmkdir linea-deploy && cd linea-deploy
forge init// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
contract HelloLinea {
function hello() external pure returns (string memory) {
return "Hello from Linea";
}
}export PRIVATE_KEY=<your-deployer-private-key>
export LINEA_RPC_URL=https://go.getblock.io/<ACCESS-TOKEN>/
forge create src/HelloLinea.sol:HelloLinea \
--rpc-url $LINEA_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcastexport ETHERSCAN_API_KEY=<your-etherscan-api-key>
forge verify-contract <contract_address> \
src/HelloLinea.sol:HelloLinea \
--chain-id 59144 \
--etherscan-api-key $ETHERSCAN_API_KEYmkdir linea-deploy && cd linea-deploy
npm init -y
npm install --save-dev hardhat
npx hardhat initrequire('@nomicfoundation/hardhat-toolbox');
const PRIVATE_KEY = process.env.PRIVATE_KEY;
module.exports = {
solidity: '0.8.30',
networks: {
linea: {
url: 'https://go.getblock.io/<ACCESS-TOKEN>/',
chainId: 59144,
accounts: [PRIVATE_KEY]
},
lineaSepolia: {
url: 'https://go.getblock.io/<ACCESS-TOKEN>/',
chainId: 59141,
accounts: [PRIVATE_KEY]
}
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY
}
};// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
contract HelloLinea {
function hello() external pure returns (string memory) {
return "Hello from Linea";
}
}const hre = require('hardhat');
async function main() {
const contract = await hre.ethers.deployContract('HelloLinea');
await contract.waitForDeployment();
console.log('HelloLinea deployed to:', await contract.getAddress());
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});npx hardhat compile
npx hardhat run scripts/deploy.js --network lineanpx hardhat verify --network linea <contract_address>