1

I am a web3 developer and want to use Base Chain layer 2 solution for my contract, but i am little confused.

  1. Does just deploying on base testnet enables all benefit of layer2?
  2. How to use Base protocol addresses, l1 contract addresses and l2 contract addresses from here ??

2 Answers 2

1

if you want to use Base protocol addresses, L1 contract addresses, and L2 contract addresses, you will need to use Base Chain JS SDK or another compatible Ethereum development kit.

Here is the general guide for how to use the Base Chain JS SDK to interact with Base Chain Layer 2 network:

Install the Base Chain JavaScript SDK using npm

npm install @eth-optimism/ovm-contracts

import skd and setup

const { providers, Wallet } = require('ethers');
const { getDefault, JsonRpcprovider } = providers;
const { OVM_MessengerWrapper } = require('@eth-optimism/contracts');
const { OptimismProvider } = require('@eth-optimism/ovm-provider');
const { Wallet } = require('ethers');
const { getFactoryContract } = require('@eth-optimism/contracts');
const { abi } = require('./abi.json');

const provider = new OptimismProvider('provider', getDefault('kovan'));
const wallet = new Wallet(privateKey, provider);
const messengerWrapper = await getFactoryContract('OVM_MessengerWrapper').connect(wallet).deploy();
const messengerAddress = messengerWrapper.address;
const l2Provider = new OptimismProvider('provider', new JsonRpcprovider('https://kovan.infura.io/v3/<project-id>'));

Use the SDK to interact with L1 and L2 contracts:

const contractAddL1 = '<L1-contract-addr>';
const contractAddL2 = '<L2-contract-addr>';
const contractABI = abi;


const contractL1 = new ethers.Contract(contractAddL1, contractABI, wallet);

const contractL2 = new ethers.Contract(contractAddL2, contractABI, l2Provider);

by following these steps, you can interact with L1 and L2 contracts using the Base Chain JavaScript SDK.

please accept and upvote the answer if it helps

2
  • Tell me if im right, when we deploy in normal testnet like sepolia, goerli then it is Layer 1 contract, and when i deploy in base testnet then it becomes layer2 contract. right?
    – Hacek
    Commented Apr 10, 2023 at 11:25
  • hello, could u pls clear my this doubt?
    – Hacek
    Commented Apr 10, 2023 at 17:04
0

Deploying your contract on Base Testnet allows you to test and experiment with the Layer 2 solution in a sandboxed environment.

This is essential for ensuring your contract works correctly with the before deploying it to mainnet (which hasn't launched yet).

Once your contract is successfully deployed and functioning, you'll be able to realize the benefits of Base, such as faster transaction speeds and reduced gas costs. However, keep in mind that the real benefits will only come into play when you deploy your contract on mainnet.

Regarding your questions:

  1. Yes it does, because Base is EVM compatible -- this means what runs on Ethereum mainnet will also run on Base.

  2. These are smart contract addresses you may find you want to reference when building (d)apps. Whether or not you need them will depend more on the type of application you're developing.

Hope this helps!

4
  • thanks @wbnns, for my 2nd question can u provide me a link of code where these addresses has been used? i just wanna see how to use it.
    – Hacek
    Commented Apr 25, 2023 at 1:07
  • @Hacek Heya! Cheers! Here's a basic tutorial. If you have any other questions, just let me know. 🤝
    – wbnns
    Commented Apr 25, 2023 at 13:20
  • I use foundry, so what should i do in case of foundry?
    – Hacek
    Commented Apr 25, 2023 at 15:40
  • @Hacek Awesome! Super easy to do, here's a tutorial for that too.
    – wbnns
    Commented Apr 25, 2023 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.