Skip to content

gelatodigital/how-tos-17-optimism-bridging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Optimism Bridge Examples

Simple examples for bridging assets between Ethereum L1 (Sepolia) and Optimism L2 (Optimism Sepolia) using the OP Stack.

🚀 Quick Start

  1. Install dependencies

    yarn install
  2. Set up environment

    cp .env.example .env
    # Edit .env with your private key
  3. Run examples

    # Deposit native ETH from L1 to L2
    yarn native-deposit
    
    # Deposit ERC20 tokens from L1 to L2
    yarn erc20-deposit
    
    # Withdraw native ETH from L2 to L1
    yarn native-withdrawal
    
    # Withdraw ERC20 tokens from L2 to L1
    yarn erc20-withdrawal
    
    # Check withdrawal status
    yarn withdrawal-status

📁 Project Structure

src/
├── config/
│   ├── clients.ts      # Viem clients configuration
│   ├── erc20ABI.ts     # ERC20 contract ABI
│   └── logger.ts       # Logging utility
├── parentToChild/      # L1 → L2 operations
│   ├── nativeDeposit.ts
│   └── erc20Deposit.ts
├── childToParent/      # L2 → L1 operations
│   ├── nativeWithdrawal.ts
│   └── erc20Withdrawal.ts
└── getWithdrawlStatus/
    └── index.ts        # Check withdrawal status

🔧 Configuration

Environment Variables

Create a .env file in the root directory:

PRIVATE_KEY=your_private_key_here

Networks

  • L1 & L2 : Configure networks in config/clients.ts

📝 Available Scripts

Script Description
yarn native-deposit Deposit native ETH from L1 to L2
yarn erc20-deposit Deposit ERC20 tokens from L1 to L2
yarn native-withdrawal Withdraw native ETH from L2 to L1
yarn erc20-withdrawal Withdraw ERC20 tokens from L2 to L1
yarn withdrawal-status Check withdrawal status

🔄 Bridge Process

Deposits (L1 → L2)

  1. Native ETH: Single transaction, instant on L2
  2. ERC20: Two transactions (approve + deposit), instant on L2

Withdrawals (L2 → L1)

  1. Initiate: Submit withdrawal on L2
  2. Prove: Prove withdrawal on L1
  3. Finalize: Finalize withdrawal on L1

Dependencies

  • @eth-optimism/viem: Optimism-specific Viem actions
  • viem: Ethereum client library
  • typescript: Type safety

📚 Resources

🤝 Contributing

Feel free to submit issues and enhancement requests!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published