Skip to main content

Deploying Smart Contracts

This guide covers deploying Solidity smart contracts on Monolythium.

Prerequisites

  • LYTH tokens for gas
  • MetaMask connected to Monolythium
  • Development environment (Hardhat or Foundry)

Using Hardhat

Setup

# Create project
mkdir my-project && cd my-project
npm init -y
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npx hardhat init

Configure Network

// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");

module.exports = {
solidity: "0.8.19",
networks: {
sprintnet: {
url: "https://rpc.sprintnet.monolythium.com:8545",
chainId: 262146,
accounts: [process.env.PRIVATE_KEY]
},
testnet: {
url: "https://rpc.testnet.monolythium.com:8545",
chainId: 262147,
accounts: [process.env.PRIVATE_KEY]
},
mainnet: {
url: "https://rpc.monolythium.com:8545",
chainId: 262148,
accounts: [process.env.PRIVATE_KEY]
}
}
};

Write Contract

// contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
_mint(msg.sender, initialSupply);
}
}

Deploy

# Set private key
export PRIVATE_KEY=your_private_key_here

# Deploy to sprintnet
npx hardhat run scripts/deploy.js --network sprintnet

Deploy script:

// scripts/deploy.js
async function main() {
const MyToken = await ethers.getContractFactory("MyToken");
const token = await MyToken.deploy(ethers.parseEther("1000000"));
await token.waitForDeployment();
console.log("Token deployed to:", await token.getAddress());
}

main().catch(console.error);

Using Foundry

Setup

curl -L https://foundry.paradigm.xyz | bash
foundryup
forge init my-project
cd my-project

Configure Network

# foundry.toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

[rpc_endpoints]
sprintnet = "https://rpc.sprintnet.monolythium.com:8545"
testnet = "https://rpc.testnet.monolythium.com:8545"
mainnet = "https://rpc.monolythium.com:8545"

Deploy

# Deploy
forge create --rpc-url sprintnet \
--private-key $PRIVATE_KEY \
src/MyToken.sol:MyToken \
--constructor-args 1000000000000000000000000

Using Remix

  1. Open Remix IDE
  2. Write your contract
  3. Compile
  4. Connect MetaMask
  5. Select "Injected Provider"
  6. Deploy

Ensure MetaMask is connected to Monolythium network.

Verification

Contract Verification

If block explorer supports verification:

# Hardhat verify
npx hardhat verify --network sprintnet <contract-address> <constructor-args>

# Foundry verify
forge verify-contract <contract-address> src/MyToken.sol:MyToken \
--chain-id 262146 \
--constructor-args $(cast abi-encode "constructor(uint256)" 1000000000000000000000000)

Gas Estimation

// Estimate deployment gas
const factory = await ethers.getContractFactory("MyToken");
const deployTx = factory.getDeployTransaction(ethers.parseEther("1000000"));
const estimatedGas = await provider.estimateGas(deployTx);
console.log("Estimated gas:", estimatedGas);

Best Practices

  1. Test on Sprintnet first - Use testnet before mainnet
  2. Verify contracts - Published source builds trust
  3. Audit critical contracts - Security review for production
  4. Use OpenZeppelin - Battle-tested implementations
  5. Check gas costs - Optimize before deployment

Troubleshooting

Deployment Failed

  • Check LYTH balance for gas
  • Verify RPC endpoint is correct
  • Increase gas limit if needed

Contract Not Found

  • Verify deployment transaction succeeded
  • Correct contract address
  • Correct network

Verification Failed

  • Match exact compiler version
  • Same optimization settings
  • Correct constructor arguments