Building on LazAI
LazAI provides a robust environment for deploying and testing smart contracts. This guide will help you choose the right development framework and get started with your first smart contract deployment.
Network Information
| LazAI Testnet | |
|---|---|
| Chain ID | 133718 | 
| Currency Symbol | LAZAI | 
| RPC | https://testnet.lazai.network | 
| Block Explorer | https://testnet-explorer.lazai.network | 
| Faucet | LazAI Testnet Faucet (Telegram) | 
Contract Addresses
| Contract | Address (LazAI Testnet | 
|---|---|
| Data Registry | 0xEAd077726dC83ecF385e3763ed4A0A50E8Ac5AA0 | 
| Verified Computing | 0x815da22D880E3560bCEcc85b6e4938b30c8202C4 | 
| Data Anchoring Token (DAT) | 0x2eD344c586303C98FC3c6D5B42C5616ED42f9D9d | 
Note: The contract address might change during the testnet phase, so please check this page regularly for updates.
Prerequisites
Before you begin, ensure you have the following installed:
- Node.js (v14+)
- npm or yarn
- Git
Choose Your Development Framework
Hardhat Development
JavaScript-based development environment with extensive plugin ecosystem
Foundry Development
Rust-based toolkit with fast compilation and testing capabilities
Framework Comparison
Hardhat
- JavaScript/TypeScript Support: Native support for JavaScript and TypeScript development
- Rich Plugin Ecosystem: Extensive collection of plugins for various development needs
- Built-in Testing Framework: Comprehensive testing capabilities with Chai and Mocha
- Developer Experience: Great for beginners with excellent debugging tools
Foundry
- Solidity-Native Testing: Write tests in Solidity for better integration
- Fast Compilation: Optimized compilation process for quick development cycles
- Built-in Fuzzing: Advanced testing capabilities with fuzzing support
- Advanced Debugging: Comprehensive debugging tools for smart contracts
Hardhat
Deploying a Counter Contract with Hardhat
This guide will walk you through deploying a counter contract using Hardhat, a popular JavaScript-based development environment for Ethereum.
1. Prerequisites
Before you begin, ensure you have:
- Node.js installed (v12 or later)
- npm (comes with Node.js)
- A code editor (e.g., VS Code)
- (Optional) MetaMask wallet and testnet tokens for deployment
2. Install Hardhat
Open your terminal and create a new project directory:
mkdir counter-project
cd counter-projectInitialize a new npm project:
npm init -yInstall Hardhat and required dependencies:
npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox dotenvnpm install --save-dev @nomicfoundation/hardhat-ignition3. Create a New Hardhat Project
Run the Hardhat setup wizard:
npx hardhatChoose “Create a JavaScript project” when prompted.
This will create a project structure like:
- contracts/- for Solidity contracts
- igntion/- for deployment scripts
- test/- for tests
- hardhat.config.js- configuration file
4. Write Your Smart Contract
Create a new file in the contracts directory, Counter.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
 
contract Counter {
    uint256 private count;
 
    function increment() public {
        count += 1;
    }
 
    function decrement() public {
        count -= 1;
    }
 
    function getCount() public view returns (uint256) {
        return count;
    }
}5. Compile the Smart Contract
Compile your contracts with:
npx hardhat compileYou should see a success message if there are no errors.
6. Write a Deployment Script
Create a new file in the ignition directory, Counter.js:
const { buildModule } = require("@nomicfoundation/hardhat-ignition/modules");
 
module.exports = buildModule("CounterModule", (m) => {
  const counter = m.contract("Counter");
 
  return { counter };
});7. Configure Network Settings
Create a .env file in your project root:
PRIVATE_KEY=your_private_key_hereEdit hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
 
module.exports = {
  solidity: "0.8.28",
  networks: {
    hardhat: {
      chainId: 31337,
    },
    lazai: {
      url: "https://testnet.lazai.network",
      chainId: 133718,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};8. Deploy Your Contract
Local Deployment (Optional)
Start the Hardhat local node in a separate terminal:
npx hardhat nodeDeploy to local network:
npx hardhat ignition deploy ignition/modules/Counter.js --network  localhostDeploy to LazAI Testnet
Make sure to:
- Get testnet tokens from the faucet
- Add your private key to the .envfile
- Never share your private key
Deploy to LazAI:
npx hardhat ignition deploy ignition/modules/Counter.js --network lazaiTesting
Test Setup
Create test/Counter.js:
const { expect } = require("chai");
 
describe("Counter", function () {
  it("Should increment the counter", async function () {
    const Counter = await ethers.getContractFactory("Counter");
    const counter = await Counter.deploy();
    await counter.deployed();
 
    await counter.increment();
    expect(await counter.getCount()).to.equal(1);
  });
});Running Tests
npx hardhat testNext Steps
- Add more complex functionality to your counter contract
- Implement events for better tracking
- Add access control mechanisms
- Set up continuous integration
- Add more comprehensive tests
Foundry
Deploying a Counter Contract with Foundry
This guide will walk you through deploying a counter contract using Foundry, a fast and portable toolkit for Ethereum application development.
1. Prerequisites
Before you begin, make sure you have:
- A code editor (e.g., VS Code)
- Git installed
- (Optional) MetaMask wallet for deploying to testnets
- (Optional) RPC endpoint for deploying to a network
2. Install Foundry
Open your terminal and run:
curl -L https://foundry.paradigm.xyz | bashThis installs foundryup, the Foundry installer.
Next, run:
foundryupThis will install the Foundry toolchain (forge, cast, anvil, chisel).
Check the installation:
forge --version3. Initialize a New Project
Create a new directory for your project and initialize Foundry:
forge init Counter
cd CounterThis creates a project with the following structure:
- src/- for your smart contracts
- test/- for Solidity tests
- script/- for deployment scripts
- lib/- for dependencies
- foundry.toml- project configuration file
4. Explore the Counter Contract
Foundry initializes your project with a Counter contract in src/Counter.sol:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
 
contract Counter {
    uint256 public number;
 
    function setNumber(uint256 newNumber) public {
        number = newNumber;
    }
 
    function increment() public {
        number++;
    }
}This contract stores a number and allows you to set or increment it.
5. Compile the Contract
Compile your smart contracts with:
forge buildThis command compiles all contracts in src/ and outputs artifacts to the out/ directory.
6. Run Tests
Foundry supports writing tests in Solidity (in the test/ directory). To run all tests:
forge testYou’ll see output indicating which tests passed or failed. The default project includes a sample test for the Counter contract.
7. Deploying Your Contract
To deploy your contract to the LazAI testnet, you’ll need:
- An RPC URL
- A private key with testnet LAZAI
Example deployment command for LazAI testnet:
forge create --rpc-url https://testnet.lazai.network \
  --private-key <YOUR_PRIVATE_KEY> \
  src/Counter.sol:Counter \
  --broadcastReplace <YOUR_PRIVATE_KEY> with your actual private key. Never share your private key.
8. Interacting with Contracts
You can use cast to interact with deployed contracts, send transactions, or query data. For example, to read the number variable on LazAI testnet:
cast call <CONTRACT_ADDRESS> "number()(uint256)" --rpc-url https://testnet.lazai.networkNext Steps
- Add more complex functionality to your counter contract
- Implement events for better tracking
- Add access control mechanisms
- Set up continuous integration
- Add more comprehensive tests