Interacting with Rollux contracts
Rollux is composed, in part, of a series of smart contracts on both L1 (Syscoin) and L2 (Rollux). You may want to interact with these 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!
On this page we'll show you how to work with these contracts directly from other contracts and how to work with them from the client side.
# Finding contract addresses
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 Rollux monorepo's deployments folder (opens new window) which contains the contract addresses for each network. You can also find them in the contracts
package (opens new window).
# Interacting from another contract
All you need to interact with the Rollux 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 or Yarn
We export a package @eth-optimism/contracts
(opens new window) that makes it easy to use the Rollux contracts within NPM or Yarn based projects.
Install the package as follows:
npm install @eth-optimism/contracts
# Importing contracts
Simply import the desired contract or interface from the @eth-optimism/contracts
package:
import { SomeRolluxContract } from "@eth-optimism/contracts/path/to/SomeRolluxContract.sol";
Please note that path/to/SomeRolluxContract
is the path to the contract within this folder (opens new window).
For example, if you wanted to import the L1CrossDomainMessenger
(opens new window) contract, you would use the following import:
import { L1CrossDomainMessenger } from "@eth-optimism/contracts/L1/messaging/L1CrossDomainMessenger.sol";
# Getting L2 contract addresses
Addresses of system contracts on the L2 side of the network are the same on every network.
We provide these addresses as constants within the Lib_PredeployAddresses
(opens new window) contract.
# Interacting from the client side
Just like when interacting from another contract, we've created a few packages that make it easy to interact with the ORollux system contracts from the client side.
# Installing via NPM or Yarn
You can use the @eth-optimism/contracts
(opens new window) package to interact with the Rollux system contracts from a JavaScript or TypeScript based project.
Install the package as follows:
npm install @eth-optimism/contracts
# Getting contract artifacts, interfaces, and ABIs
You can get the compiler artifact, bytecode, and ABI for any Rollux contract as follows:
import { getContractDefinition } from '@eth-optimism/contracts'
const artifact = getContractDefinition('SomeRolluxContract')
const abi = artifact.abi
const bytecode = artifact.bytecode
const deployedBytecode = artifact.deployedBytecode
2
3
4
5
6
Similarly, you can also get ethers Interface objects (opens new window) for any contract:
import { getContractInterface } from '@eth-optimism/contracts'
const iface = getContractInterface('SomeRolluxContract')
2
3
# Getting L2 contract addresses
You can get the address of any L2 contract as follows:
import { predeploys } from '@eth-optimism/contracts'
const address = predeploys.CONTRACT_NAME_GOES_HERE
2
3