docs icon indicating copy to clipboard operation
docs copied to clipboard

[DOCS] Suggestion to Add Example for Custom Chains in [Bridging ETH to OP Mainnet with Viem-Supported Networks]

Open opfocus opened this issue 11 months ago • 3 comments

I suggest adding the following example to the Supported Networks section to help users more easily adapt it to their own custom chains.

By modifying the code below with the appropriate values for their own test networks, users can quickly configure and integrate their custom OP Stack chains.

const { defineChain } = require('viem');
const { chainConfig } = require('viem/op-stack')

const sourceId = 11_155_111 // sepolia

const optimismSepolia = /*#__PURE__*/ defineChain({
  ...chainConfig,
  id: 11155420,
  name: 'OP Sepolia',
  nativeCurrency: { name: 'Sepolia Ether', symbol: 'ETH', decimals: 18 },
  rpcUrls: {
    default: {
      http: ['https://sepolia.optimism.io'],
    },
  },
  blockExplorers: {
    default: {
      name: 'Blockscout',
      url: 'https://optimism-sepolia.blockscout.com',
      apiUrl: 'https://optimism-sepolia.blockscout.com/api',
    },
  },
  contracts: {
    ...chainConfig.contracts,
    disputeGameFactory: {
      [sourceId]: {
        address: '0x05F9613aDB30026FFd634f38e5C4dFd30a197Fa1',
      },
    },
    l2OutputOracle: {
      [sourceId]: {
        address: '0x90E9c4f8a994a250F6aEfd61CAFb4F2e895D458F',
      },
    },
    multicall3: {
      address: '0xca11bde05977b3631167028862be2a173976ca11',
      blockCreated: 1620204,
    },
    portal: {
      [sourceId]: {
        address: '0x16Fc5058F25648194471939df75CF27A2fdC48BC',
      },
    },
    l1StandardBridge: {
      [sourceId]: {
        address: '0xFBb0621E0B23b5478B630BD55a5f21f67730B0F1',
      },
    },
  },
  testnet: true,
  sourceId,
})

This code is from the chains/definitions/optimismSepolia.ts file in the viem package, with slight modifications.

opfocus avatar Mar 06 '25 19:03 opfocus

Hi @opfocus , thanks for this suggestion! I'll look into it early next week and get it implemented soon once approved!

bradleycamacho avatar Mar 06 '25 21:03 bradleycamacho

I encountered an error while executing the following step, Maybe publicClientL1.buildInitiateWithdrawal should be used here[tested]. I noticed that there seems to be no introduction to the buildWithdrawalTransaction function in the viem documentation

const withdrawalArgs = await publicClientL2.buildWithdrawalTransaction({
                                            ^

TypeError: publicClientL2.buildWithdrawalTransaction is not a function
    at file:///D:/crosss-dom/index.js:20:45
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

opfocus avatar Mar 10 '25 18:03 opfocus

I encountered an error while executing the following step, Maybe publicClientL1.buildInitiateWithdrawal should be used here[tested]. I noticed that there seems to be no introduction to the buildWithdrawalTransaction function in the viem documentation

const withdrawalArgs = await publicClientL2.buildWithdrawalTransaction({
                                            ^

TypeError: publicClientL2.buildWithdrawalTransaction is not a function
    at file:///D:/crosss-dom/index.js:20:45
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Hello @opfocus , thanks for pointing this, i'll look into this and update accordingly.

krofax avatar Mar 11 '25 15:03 krofax

Updated this tutorial

krofax avatar Sep 11 '25 19:09 krofax