Oraichain
  • ORAICHAIN
    • Introduction
    • System Overview
      • AI Layer 1 for Data Economy & blockchain oracle services
      • Layer 2 Rollups and Subnetworks
      • Verifiable and trustless AI Execution
      • Protocol Messages
      • IBC Integration
    • Use Cases
    • Token Economics
  • DEVELOPER GUIDES
    • General
      • Blockchain details
    • CosmWasm Contracts
      • Compile a Contract
      • Deploy a Contract
      • Query a Contract
      • Send tokens to a Contract
      • Manage Contracts using design patterns
      • End-to-end CosmWasm testing with CW-simulate
    • Local testnet chain
    • Wallet
      • OWallet
    • Price Feed
      • CW Oracle Hub
    • VRF 2.0
      • Introduction to Oraichain VRF 2.0
      • Get a Random Value from API
        • Get VRF Value from different networks
        • Contract Addresses and Pricing
        • Validate a Group Signature
      • Security Remarks
      • API Reference
      • Get support from Oraichain team
    • OraiDEX
      • ORAIX Token
      • OBridge
        • OraiBTC
        • TON Bridge
          • TON Blockchain 101
      • Decentralization
    • Indexers
      • SubQuery
    • OraichainEVM
      • Getting started
      • Smart Contracts
        • Oraichain EVM Precompiled Contracts
        • Address
        • Bank
        • Wasm
        • Authz
      • Guides
        • Metamask
        • Remix
        • Foundry
        • Hardhat
        • Tools
        • Oraichain EVM RPC
  • GOVERNANCE
    • Privacy Policy
  • NODES & VALIDATORS
    • Networks
      • Joining Mainnet
        • Build Linux binary from source and become a Sentry Node Operator
        • Become a Validator
      • Joining Testnet
        • Become Testnet Fullnode From Source
        • StateSync Testnet
        • Faucet Testnet
    • Oraichain Tutorials
      • Migrate one Oraichain node to another
      • Cosmovisor
      • Update validator image
      • Tenderduty
      • Grafana
      • Tracking Unvoted Proposals
      • Tmtop
Powered by GitBook
On this page
  • Create Foundry Project
  • Anvil
  • Deploy Contract
  • Run Foundry Tests
  • Run Foundry Script

Was this helpful?

Edit on GitHub
  1. DEVELOPER GUIDES
  2. OraichainEVM
  3. Guides

Foundry

Install OraichainEVM by following the full instructions provided in the documentation.

Create Foundry Project

Create a directory for your contracts and initialize it:

forge init oraichain-evm-foundry
cd oraichain-evm-foundry

For now, let’s check what the default template looks like:

tree . -d -L 1
.
├── lib
├── script
├── src
└── test

5 directories

Open src/Counter.sol with the following contract:

```solidity
// 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++;
    }
}

```

Compile the contract:

forge build

Anvil

Anvil is a fast local Ethereum development node.

To fork against a live OraichainEVM network run:

anvil --fork-url <RPC_URL>

Deploy Contract

Migrate your contract in the foundry terminal:

forge create src/Counter.sol:Counter --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --broadcast

You should see deployment logs in the OraichainEVM terminal for each transaction.

Run Foundry Tests

Run the tests using the OraichainEVM node:

forge test test/Counter.t.sol --rpc-url <RPC_URL>

This will confirm the contract's functionality.

Run Foundry Script

To execute a script on OraichainEVM, run:

forge script script/Counter.s.sol --rpc-url <RPC_URL>

earched Pre-requisite reading installation run a node search.

For suggestions, contribute on GitHub!

PreviousRemixNextHardhat

Last updated 1 month ago

Was this helpful?

Anvil is part of the Foundry suite and is installed alongside forge, cast and chisel. If you haven’t installed Foundry yet, see .

Foundry installation