Deploy Your First Contract in 5 Minutes
Liberty Chain is fully EVM-compatible, so you can use the same tools you already know from Ethereum development. This quickstart walks you through deploying a simple smart contract using Hardhat, with a brief Foundry alternative at the end.
Prerequisites
- Node.js 18+ — download from nodejs.org
- A wallet with test ETH — follow the Get Test ETH guide if you have not done this yet.
- Your wallet private key — exported from MetaMask or your preferred wallet. Never share this or commit it to version control.
Private Key Safety
.env file (added to .gitignore) to store sensitive values.1. Initialize a Hardhat Project
mkdir my-liberty-project && cd my-liberty-project
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenv
npx hardhat initSelect "Create a JavaScript project" when prompted and accept the defaults.
2. Configure the Network
Create a .env file in your project root:
PRIVATE_KEY=your_wallet_private_key_hereUpdate hardhat.config.js to add Liberty Chain Testnet:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.24",
networks: {
libertyTestnet: {
url: "https://testnet-rpc.lcx.com",
chainId: 76847801,
accounts: [process.env.PRIVATE_KEY],
},
},
etherscan: {
apiKey: {
libertyTestnet: "not-needed",
},
customChains: [
{
network: "libertyTestnet",
chainId: 76847801,
urls: {
apiURL: "https://testnet-explorer.lcx.com/api",
browserURL: "https://testnet-explorer.lcx.com",
},
},
],
},
};3. Write the Contract
Create a simple storage contract at contracts/Storage.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Storage {
uint256 private _value;
event ValueChanged(uint256 newValue);
function store(uint256 value) public {
_value = value;
emit ValueChanged(value);
}
function retrieve() public view returns (uint256) {
return _value;
}
}4. Write the Deploy Script
Create a deployment script at scripts/deploy.js:
const hre = require("hardhat");
async function main() {
const Storage = await hre.ethers.getContractFactory("Storage");
const storage = await Storage.deploy();
await storage.waitForDeployment();
const address = await storage.getAddress();
console.log("Storage deployed to:", address);
// Store a value
const tx = await storage.store(42);
await tx.wait();
console.log("Stored value: 42");
// Read it back
const value = await storage.retrieve();
console.log("Retrieved value:", value.toString());
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});5. Deploy to Liberty Chain
Compile the contract and deploy it to Liberty Chain Testnet:
npx hardhat compile
npx hardhat run scripts/deploy.js --network libertyTestnetYou should see output similar to:
Storage deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
Stored value: 42
Retrieved value: 42Fast Confirmations
6. Verify on Blockscout
Verify your contract source code on the Liberty Chain block explorer so anyone can read and interact with it:
npx hardhat verify --network libertyTestnet <DEPLOYED_CONTRACT_ADDRESS>Replace <DEPLOYED_CONTRACT_ADDRESS> with the address printed during deployment. Once verified, you can view and interact with your contract on the Liberty Chain Explorer.
Alternative: Foundry
If you prefer Foundry, you can deploy to Liberty Chain with forge:
# Install Foundry (if not already installed)
curl -L https://foundry.paradigm.xyz | bash
foundryup
# Create a new project
forge init my-liberty-project && cd my-liberty-project
# Deploy to Liberty Chain Testnet
forge create --rpc-url https://testnet-rpc.lcx.com \
--private-key $PRIVATE_KEY \
src/Counter.sol:Counter
# Verify on Blockscout
forge verify-contract <ADDRESS> src/Counter.sol:Counter \
--verifier blockscout \
--verifier-url https://testnet-explorer.lcx.com/apiInfo
Next Steps
- RPC API Reference — explore the available JSON-RPC methods for reading and writing data.
- Transaction Fees — understand how gas fees work on Liberty Chain.
- Differences from Ethereum — learn about the small differences you may encounter when porting contracts.
- Verify Contracts — detailed guide on contract verification with Blockscout.