Smart Contracts

Deploy and interact with smart contracts on XL3 Chain

Smart Contract Development on XL3 Chain

XL3 Chain is fully compatible with Ethereum Virtual Machine (EVM), allowing you to deploy Solidity smart contracts with minimal modifications. Enjoy faster transactions and lower gas fees.

EVM CompatibleSolidityLow Gas FeesFast Finality

Quick Start

Setup Development Environment
Install and configure Foundry for XL3 Chain development

Install Foundry:

curl -L https://foundry.paradigm.xyz | bash

Initialize Project:

forge init my-xl3-project
Network Configuration
Configure your project to deploy on XL3 Chain

foundry.toml:

[profile.default]
src = "src"
out = "out"
libs = ["lib"]

[rpc_endpoints]
xl3 = "https://rpc.xl3chain.com"

[etherscan]
xl3 = { key = "YOUR_API_KEY" }

Contract Examples

Simple Token Contract
A basic ERC-20 token implementation for XL3 Chain
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

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

contract XL3Token is ERC20, Ownable {
    constructor(
        string memory name,
        string memory symbol,
        uint256 initialSupply
    ) ERC20(name, symbol) Ownable(msg.sender) {
        _mint(msg.sender, initialSupply * 10**decimals());
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}
NFT Contract
ERC-721 NFT contract optimized for XL3 Chain
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract XL3NFT is ERC721, Ownable {
    uint256 private _tokenIdCounter;
    string private _baseTokenURI;

    constructor(
        string memory name,
        string memory symbol,
        string memory baseURI
    ) ERC721(name, symbol) Ownable(msg.sender) {
        _baseTokenURI = baseURI;
    }

    function mint(address to) public onlyOwner {
        uint256 tokenId = _tokenIdCounter++;
        _safeMint(to, tokenId);
    }

    function _baseURI() internal view override returns (string memory) {
        return _baseTokenURI;
    }
}

Deployment Guide

Deploy with Foundry
Step-by-step deployment process

1. Compile Contract:

forge build

2. Deploy to XL3 Chain:

forge create --rpc-url xl3 \
--private-key $PRIVATE_KEY \
src/MyContract.sol:MyContract

3. Verify Contract:

forge verify-contract \
--chain-id 7117 \
--verifier blockscout \
--verifier-url https://exp.0xl3.com/api \
--verify \
$CONTRACT_ADDRESS \
src/MyContract.sol:MyContract
Best Practices
Security and optimization tips

Security:

  • • Use OpenZeppelin contracts
  • • Implement access controls
  • • Add reentrancy guards
  • • Validate all inputs

Gas Optimization:

  • • Use packed structs
  • • Minimize storage operations
  • • Use events for data storage
  • • Optimize loops and conditions

Testing:

  • • Write comprehensive tests
  • • Test edge cases
  • • Use fuzzing for robustness
  • • Test on testnet first

Additional Resources

Foundry Documentation

Complete guide to Foundry toolkit

View Docs

OpenZeppelin

Secure smart contract library

Browse Library

XL3 Explorer

Verify and interact with contracts

Open Explorer