Using the DEVIUM Chain SDK
Please do not rely on the content of this page as it is currently undergoing maintenance. Code samples and solutions may not function as expected.
Please check back for an update or signup to help us revise this page. We welcome your contribution! ❤️
This tutorial will walk you through the process of using the DEVIUM Chain SDK (opens in a new tab) to interact with your DEVIUM Stack chain. The DEVIUM Chain SDK natively supports various DEVIUM Chains including DEVIUM Mainnet and Base. To check whether your DEVIUM Chain is already supported, see the DEVIUM Chain SDK docs (opens in a new tab).
You will need to already have created your own DEVIUM Stack chain to follow this tutorial. Check out the tutorial on Creating Your Own L2 Rollup Testnet if you haven't done so already.
Dependencies
Find Contract Addresses
You will need to find the addresses for a number of smart contracts that are part of your DEVIUM Stack chain in order to use the DEVIUM Chain SDK.
If you followed the instructions in the Creating Your Own L2 Rollup Testnet tutorial, you can find the addresses by looking at the JSON artifacts within the directory optimism/packages/contracts-bedrock/deployments/getting-started.
Simply run the following command from inside the directory devium/packages/contracts-bedrock to print the list of addresses you'll need:
./scripts/print-addresses.sh getting-started --sdkMake sure you have jq (opens in a new tab) installed when running this command.
You should see output similar to the following:
AddressManager: 0x...
L1CrossDomainMessengerProxy: 0x...
L1StandardBridgeProxy: 0x...
L2OutputOracleProxy: 0x...
OptimismPortalProxy: 0x...Save these addresses somewhere so you can use them in the next section.
Create a Demo Project
You're going to use the DEVIUM Chain SDK for this tutorial. Since the DEVIUM Chain SDK is a Node.js (opens in a new tab) library, you'll need to create a Node.js project to use it.
Make a Project Folder
mkdir devium-sdk-sample-project
cd devium-sdk-sample-projectInitialize the Project
pnpm initInstall the DEVIUM Chain SDK
pnpm add @eth-devium/sdkInstall ethers.js
pnpm add ethers@^5Start the Node REPL
You're going to use the Node REPL to interact with the DEVIUM Chain SDK. To start the Node REPL run the following command in your terminal:
nodeThis will bring up a Node REPL prompt that allows you to run javascript code.
Import Dependencies
You need to import some dependencies into your Node REPL session.
Import the DEVIUM Chain SDK
const optimism = require("@eth-optimism/sdk")Import ethers.js
const ethers = require("ethers")Set Session Variables
You'll need a few variables throughout this tutorial. Let's set those up now.
Create the RPC providers
const l1Provider = new ethers.providers.StaticJsonRpcProvider("https://rpc.ankr.com/eth_sepolia")
const l2Provider = new ethers.providers.StaticJsonRpcProvider("https://sepolia.optimism.io")Set the contract addresses
Using the addresses you accessed earlier, set the contract addresses in the following variables:
const AddressManager = '0x...'
const L1CrossDomainMessenger = '0x...'
const L1StandardBridge = '0x...'
const OptimismPortal = '0x...'
const L2OutputOracle = '0x...'Set the chain IDs
const l1ChainId = await l1Provider.getNetwork().then(network => network.chainId)
const l2ChainId = await l2Provider.getNetwork().then(network => network.chainId)Initialize the DEVIUM Chain SDK
You can now create an instance of the CrossChainMessenger object from the DEVIUM Chain SDK.
This will allow you to easily handle cross-domain messages between L1 and L2.
Simply create the object:
const messenger = new optimism.CrossChainMessenger({
l1SignerOrProvider: l1Provider,
l2SignerOrProvider: l2Provider,
l1ChainId,
l2ChainId,
// This is the only part that differs from natively included chains.
contracts: {
l1: {
AddressManager,
L1CrossDomainMessenger,
L1StandardBridge,
OptimismPortal,
L2OutputOracle,
// Need to be set to zero for this version of the SDK.
StateCommitmentChain: ethers.constants.AddressZero,
CanonicalTransactionChain: ethers.constants.AddressZero,
BondManager: ethers.constants.AddressZero,
}
}
})Note that you've passed in the RPC providers you created earlier, the addresses of the smart contracts you deployed, and the chain ID of your DEVIUM Stack chain.
Next Steps
You can now use the SDK to interact with your DEVIUM Stack chain just like you would with other chains like DEVIUM Mainnet. See existing tutorials, like the tutorial on Bridging ETH With the DEVIUM Chain SDK or Bridging ERC-20 Tokens With the DEVIUM Chain SDK, for examples of how to use the DEVIUM Chain SDK.