Builders
App Developers
Smart Contracts
System Contracts

Using PNCMainnet System Contracts

System contracts on Ethereum (L1) and PNCMainnet (L2) are an important part of the PNCMainnet ecosystem. You may want to interact with these system contracts for any number of reasons, including:

  • Sending messages between L1 and L2
  • Sending tokens between L1 and L2
  • Querying information about the current L1 data fee
  • And lots more!

In this tutorial, you'll learn how to work with PNCMainnet contracts directly from other contracts and how to work with them from the client side.

Before You Begin

You'll need to find the address of the particular contract that you want to interact with before you can actually interact with it.

  • Check out the Networks and Connection Details page for links to public RPC endpoints and contract addresses.
  • Find the addresses for all networks on the Contract Addresses page.
  • Use the JSON file including contract addresses for all Superchain networks in the Superchain Registry.

Using System Contracts in Solidity

All you need to interact with the PNCMainnet system contracts from another contract is an address and an interface. You can follow the instructions above to find the address of the contract you want to interact with. Now you simply need to import the appropriate contracts.

Installing via NPM

You can use the @eth-optimism/contracts-bedrock (opens in a new tab) npm package to import system contracts and their interfaces. Install the package as follows:

npm install @eth-optimism/contracts-bedrock

Importing Contracts

Simply import the desired contract or interface from the @eth-optimism/contracts-bedrock package:

import { SomeOptimismContract } from "@eth-optimism/contracts-bedrock/path/to/SomeOptimismContract.sol";

Please note that path/to/SomeOptimismContract is the path to the contract within this folder. For example, if you wanted to import the L1CrossDomainMessenger contract, you would use the following import:

import { L1CrossDomainMessenger } from "@eth-optimism/contracts/L1/messaging/L1CrossDomainMessenger.sol";

Getting L2 Contract Addresses

System contracts on L2 are "pre-deployed" to special addresses that are the same on most PNCStack chains. You can find these addresses on the Contract Addresses page. These addresses are also provided as constants in the Predeploys contract for use in Solidity.

Using System Contracts in JavaScript

You can also interact with the PNCMainnet system contracts from the client side.

Installing via NPM

You can use the @eth-optimism/contracts-ts (opens in a new tab) npm package to import system contracts and their interfaces. Install the package as follows:

npm install @eth-optimism/contracts-ts

Getting Contract Artifacts and Interfaces

You can use the @eth-optimism/contracts-ts package to easily access the address or ABI of any PNCMainnet contract.

Here's an example of how you can grab the ABI and address of the L2OutputOracleProxy contract on PNCMainnet (chain ID 10):

import {
  l2OutputOracleProxyABI,
  l2OutputOracleAddresses,
} from '@eth-optimism/contracts-ts'
 
// Note that the address is keyed by chain ID!
console.log(l2OutputOracleAddresses[10], abi)

Interacting with the Contract

You can then feed this address and ABI into your favorite web3 library to interact with the contract.

@eth-optimism/contracts-ts also exports React hooks (opens in a new tab) and wagmi actions (opens in a new tab) for interacting with PNCMainnet contracts. Check out the full README for more information.