For the complete documentation index, see llms.txt. This page is also available as Markdown.
Development Setup
Overview
This guide will help you set up a complete development environment for building on OPN Chain. Whether you're new to blockchain development or an experienced Ethereum developer, you'll find everything you need to get started.
Prerequisites
Required Software
Software
Version
Purpose
Node.js
16.0+
JavaScript runtime
npm/yarn
Latest
Package management
Git
2.0+
Version control
VS Code
Latest
Recommended IDE
Optional Tools
Tool
Purpose
Docker
Container deployment
Python
For Brownie/Ape frameworks
Rust
For Foundry framework
Step 1: Install Node.js
macOS:
# Using Homebrewbrewinstallnode# Or download from nodejs.org
# Compile contracts
npx hardhat compile
# Run tests
npx hardhat test
# Run tests with gas reporting
REPORT_GAS=true npx hardhat test
# Deploy to OPN testnet
npx hardhat run scripts/deploy.js --network opnTestnet
# Verify contract
npx hardhat verify --network opnTestnet DEPLOYED_CONTRACT_ADDRESS "Constructor argument"
## Development Workflow
### 1. Write Smart Contracts
```solidity
// contracts/MyToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC20, Ownable {
constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
_mint(msg.sender, initialSupply);
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
// test/MyToken.test.js
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("MyToken", function () {
let token;
let owner;
let addr1;
let addr2;
beforeEach(async function () {
[owner, addr1, addr2] = await ethers.getSigners();
const Token = await ethers.getContractFactory("MyToken");
token = await Token.deploy(ethers.utils.parseEther("1000000"));
await token.deployed();
});
describe("Deployment", function () {
it("Should assign total supply to owner", async function () {
const ownerBalance = await token.balanceOf(owner.address);
expect(await token.totalSupply()).to.equal(ownerBalance);
});
});
describe("Transactions", function () {
it("Should transfer tokens between accounts", async function () {
await token.transfer(addr1.address, 50);
expect(await token.balanceOf(addr1.address)).to.equal(50);
await token.connect(addr1).transfer(addr2.address, 50);
expect(await token.balanceOf(addr2.address)).to.equal(50);
expect(await token.balanceOf(addr1.address)).to.equal(0);
});
});
});
# Run all tests
npx hardhat test
# Run specific test file
npx hardhat test test/MyToken.test.js
# Run with gas reporting
REPORT_GAS=true npx hardhat test
# Run with coverage
npx hardhat coverage