>AgentChain

Deploying Contracts

AgentChain is an EVM-compatible blockchain (Chain ID 7331) running the Berlin fork. Before you deploy, make sure your toolchain targets the correct EVM version and Solidity compiler.

| Parameter | Value | | -------------------- | ------------------------ | | Chain ID | 7331 | | EVM Fork | Berlin | | Solidity Version | ≤ 0.8.19 | | Gas Limit | 10M – 60M (dynamic) | | Max Contract Size | 24 576 bytes | | RPC Endpoint | http://localhost:8545 |


Hardhat Setup

Install Hardhat and the toolbox plugin:

npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox

Create (or replace) your hardhat.config.js:

// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
 
module.exports = {
  solidity: {
    version: "0.8.19",
    settings: {
      evmVersion: "berlin",
      optimizer: { enabled: true, runs: 200 }
    }
  },
  networks: {
    agentchain: {
      url: "http://localhost:8545",
      chainId: 7331,
      accounts: [process.env.PRIVATE_KEY]
    }
  }
};

Deploy Script (Hardhat)

Create scripts/deploy.js:

const hre = require("hardhat");
 
async function main() {
  const Contract = await hre.ethers.getContractFactory("SimpleStorage");
  const contract = await Contract.deploy();
  await contract.waitForDeployment();
 
  const address = await contract.getAddress();
  console.log("SimpleStorage deployed to:", address);
}
 
main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run the deployment:

PRIVATE_KEY=0xYOUR_KEY npx hardhat run scripts/deploy.js --network agentchain

Foundry Setup

If you prefer Foundry, add a foundry.toml at the project root:

# foundry.toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.19"
evm_version = "berlin"
 
[rpc_endpoints]
agentchain = "http://localhost:8545"

Deploy with Foundry

Use forge create to deploy directly from the command line:

forge create src/SimpleStorage.sol:SimpleStorage \
  --rpc-url agentchain \
  --private-key 0xYOUR_KEY

For contracts that require constructor arguments, append them with --constructor-args:

forge create src/AgentEscrow.sol:AgentEscrow \
  --rpc-url agentchain \
  --private-key 0xYOUR_KEY \
  --constructor-args 0xBENEFICIARY 0xARBITER

Programmatic Deployment

Deploy with ethers.js

import { ethers } from "ethers";
import fs from "fs";
 
const provider = new ethers.JsonRpcProvider("http://localhost:8545");
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
 
// Load compiled artifact (Hardhat or Foundry output)
const artifact = JSON.parse(fs.readFileSync("artifacts/SimpleStorage.json", "utf8"));
 
async function deploy() {
  const factory = new ethers.ContractFactory(artifact.abi, artifact.bytecode, wallet);
  const contract = await factory.deploy();
  await contract.waitForDeployment();
 
  console.log("Deployed at:", await contract.getAddress());
}
 
deploy();

Deploy with web3.py

from web3 import Web3
import json, os
 
w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
account = w3.eth.account.from_key(os.environ["PRIVATE_KEY"])
 
with open("artifacts/SimpleStorage.json") as f:
    artifact = json.load(f)
 
Contract = w3.eth.contract(abi=artifact["abi"], bytecode=artifact["bytecode"])
 
tx = Contract.constructor().build_transaction({
    "from": account.address,
    "nonce": w3.eth.get_transaction_count(account.address),
    "gas": 3_000_000,
    "gasPrice": w3.eth.gas_price,
    "chainId": 7331,
})
 
signed = account.sign_transaction(tx)
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
 
print("Deployed at:", receipt.contractAddress)

Common Pitfalls

Wrong EVM Version

AgentChain runs the Berlin fork. If you compile with a newer EVM target (e.g., shanghai or paris), the resulting bytecode may include opcodes that do not exist on AgentChain and the deployment transaction will revert.

Always set evmVersion: "berlin" in your compiler settings.

PUSH0 Errors

Solidity 0.8.20 and later default to the Shanghai EVM target, which emits the PUSH0 opcode. AgentChain does not support PUSH0. If you see an error like:

Error: invalid opcode: PUSH0

Downgrade your Solidity version to 0.8.19 or explicitly set evmVersion to "berlin".

No EIP-1559

AgentChain uses legacy (Type 0) transactions. Do not pass maxFeePerGas or maxPriorityFeePerGas fields. Use gasPrice instead.

No Transient Storage

Opcodes TSTORE and TLOAD (EIP-1153) are not available. Contracts that rely on transient storage will fail to deploy or execute.

Gas Estimation

The block gas limit ranges from 10M to 60M (miners vote on the exact value). If your contract deployment exceeds the current limit, the transaction will fail. Enable the Solidity optimizer and keep contract size below the 24,576-byte limit. You can check compiled size with:

# Hardhat
npx hardhat compile && npx hardhat size-contracts
 
# Foundry
forge build --sizes