Greeter contract to the OP Sepolia testnet with Foundry, then read from and write to it from the command line.
OP Stack chains are EVM equivalent, so the workflow here is the same one you’d use on Ethereum: the only OP-specific detail is the RPC endpoint and chain ID you point at.
By the end you’ll have a live contract on OP Sepolia and the commands to interact with any contract you deploy later.
This tutorial uses the OP Sepolia testnet, so you won’t spend real funds.
The same steps work on any OP Stack chain — swap in that chain’s RPC URL and fund your account on that network.
Dependencies
- Foundry — installed in the first step below.
- A terminal with
curlavailable (preinstalled on macOS and most Linux distributions).
Install Foundry
Foundry is a toolkit for Ethereum development. This tutorial uses two of its command-line tools:forge (to compile and deploy) and cast (to send transactions and read state).
Install foundryup
foundryup, Foundry’s version manager.
Follow the on-screen instructions to add it to your PATH (you may need to open a new terminal).Verify the install
Confirmforge and cast are available:
PATH instructions from foundryup and open a new terminal.
Create a project and contract
Initialize a Foundry project
forge init scaffolds a new project with src/, test/, and script/ directories.Add the Greeter contract
Replace the contents of
src/Greeter.sol with the following.
This is a variation on Hardhat’s Greeter contract: it stores a greeting string, exposes it through greet(), and lets anyone update it through setGreeting().Verify the build
forge build should report a successful compilation and write artifacts to the out/ directory.
If compilation fails, check that src/Greeter.sol matches the code above exactly.
Configure OP Sepolia and your account
You need two things to deploy: an RPC endpoint for OP Sepolia and a private key to sign the deployment transaction.Create a deployment account
Create a fresh key for this tutorial rather than reusing a key that holds real funds.This prints an
Address and a Private key.
Save both somewhere safe.https://sepolia.optimism.io is a public, rate-limited endpoint suited to development and testing.
For a full list of endpoints and production providers, see the OP Stack RPC directory.
For OP Sepolia’s chain ID (11155420) and other network parameters, see Connecting to OP Mainnet.Fund your account
Deploying a contract costs gas, so your account needs testnet ETH on OP Sepolia.Request testnet ETH
Use the Superchain Faucet to send OP Sepolia ETH to your
ACCOUNT_ADDRESS.Verify your balance
Check that the faucet funds have arrived before deploying:0 before continuing.
Deploy the contract
DeployGreeter to OP Sepolia and capture the resulting contract address.
forge create command compiles (if needed), signs, and broadcasts the deployment transaction.
Its output includes a Deployed to: line; the awk command extracts that address into the CONTRACT_ADDRESS variable so you can reuse it in the next step.
Run
forge create on its own (without the awk pipe) if you want to see the full output — the deployer address, the new contract address, and the transaction hash.Verify the deployment
Confirm the contract exists on-chain by fetching its bytecode:0x, the deployment didn’t land — re-check your balance and rerun the deploy step.
Interact with the contract
Now read from and write to your live contract usingcast.
View your contract on the block explorer
Open an OP Sepolia block explorer and search for yourCONTRACT_ADDRESS to see the deployment transaction and the setGreeting call you just sent.
Publishing (verifying) your contract’s source code on the explorer is optional but recommended, because it lets anyone read and interact with the contract from the explorer UI.
Next steps
- Learn the broader conventions in Building apps on OP Stack chains.
- Understand the differences between Ethereum and OP Stack chains.
- Try a cross-chain tutorial next, such as bridging ERC-20 tokens.