Deploy a smart contract on X-Layer

X Layer is EVM-equivalent, so contracts deploy with the standard Solidity toolchain — Foundry, Hardhat, or Remix — pointed at a GetBlock endpoint, with no chain-specific compiler or plugin required. The one difference from an Ethereum deploy is that gas is paid in OKB. This guide covers adding the network to a wallet and deploying a first contract to X Layer.

Prerequisites

  • Node.js 18+ and a package manager, or Foundry
  • An EVM wallet (such as MetaMask) with OKB on X Layer for gas — see Add Network to Your Wallet and Funding Your Deployer
  • A GetBlock access token — the endpoint is https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
  • A funded deployer address with OKB on X Layer

Network Details

PropertyValue
Network NameX Layer Mainnet
RPC URLhttps://shared.eu-central-1.getblock.io//
Chain ID196 (0xc4)
Currency SymbolOKB
Block Explorerwww.oklink.com/xlayer

Add Network to Your Wallet

Ethereum Mainnet is pre-configured in MetaMask by default. X Layer is not, so it must be added manually — follow the steps below:

  1. Open your wallet

    Open MetaMask (or your EVM wallet of choice).

  2. Add a custom network

    Open the network selector and choose Add a custom network.

  3. Enter the network details

    Enter the values from the Network Details table above.

  4. Confirm the chain ID

    Confirm the Chain ID resolves to 196.

  5. Save and switch networks

    Save and switch to the newly added X Layer network.

Funding Your Deployer

X Layer gas is paid in OKB.

  • Mainnet — bridge OKB into X Layer through the official X Layer bridge, or acquire it on OKX, then send it to your deployer's address.

Deploy with Foundry

  1. Install Foundry and initialize

    bashcurl -L https://foundry.paradigm.xyz | bash
    foundryup
    forge init hello-xlayer && cd hello-xlayer
  2. Write the contract

    src/Hello.sol

    solidity// SPDX-License-Identifier: MIT
    pragma solidity ^0.8.24;
    
    contract Hello {
        string public greeting = "Hello, X Layer";
    
        function setGreeting(string calldata greeting_) external {
            greeting = greeting_;
        }
    }
  3. Deploy

    bashexport XLAYER_RPC_URL=https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
    export PRIVATE_KEY=0xyour_deployer_private_key
    
    forge create src/Hello.sol:Hello \
      --rpc-url $XLAYER_RPC_URL \
      --private-key $PRIVATE_KEY \
      --broadcast
  4. Verify on the block explorer

    X Layer uses the OKLink explorer, which provides an Etherscan-compatible verification API:

    bashforge verify-contract <DEPLOYED_ADDRESS> src/Hello.sol:Hello \
      --chain-id 196 \
      --verifier etherscan \
      --verifier-url https://www.oklink.com/api/v5/explorer/xlayer/api \
      --etherscan-api-key <OKLINK_API_KEY>

Deploy with Hardhat

  1. Create the project

    bashmkdir hello-xlayer && cd hello-xlayer
    npm init --yes
    npm install --save-dev hardhat
    npx hardhat init
  2. Configure the network

    hardhat.config.js

    javascriptrequire('@nomicfoundation/hardhat-toolbox');
    
    const XLAYER_CHAIN_ID = 196;
    
    module.exports = {
      solidity: '0.8.24',
      networks: {
        xlayer: {
          url: process.env.XLAYER_RPC_URL,
          chainId: XLAYER_CHAIN_ID,
          accounts: [process.env.PRIVATE_KEY]
        }
      },
      etherscan: {
        apiKey: { xlayer: process.env.OKLINK_API_KEY },
        customChains: [
          {
            network: 'xlayer',
            chainId: XLAYER_CHAIN_ID,
            urls: {
              apiURL: 'https://www.oklink.com/api/v5/explorer/xlayer/api',
              browserURL: 'https://www.oklink.com/xlayer'
            }
          }
        ]
      }
    };
  3. Write the contract

    contracts/Hello.sol

    solidity// SPDX-License-Identifier: MIT
    pragma solidity ^0.8.24;
    
    contract Hello {
        string public greeting = "Hello, X Layer";
    
        function setGreeting(string calldata greeting_) external {
            greeting = greeting_;
        }
    }
  4. Deploy

    bashexport XLAYER_RPC_URL=https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/
    export PRIVATE_KEY=0xyour_deployer_private_key
    
    npx hardhat ignition deploy ./ignition/modules/Hello.js --network xlayer
  5. Verify on the block explorer

    bashexport OKLINK_API_KEY=your_oklink_api_key
    npx hardhat verify --network xlayer <DEPLOYED_ADDRESS>