Skip to main content

Optimism-Python: Unofficial Python Client for the OP-Stack

This library is a Python implementation of the OP-Stack SDK. It tries to mirror some of the core functionalities such as:

  • providing easy access to the OP-Stack contracts
  • bridging of assets from L1 to L2 (deposits) and vice-versa (withdrawls)
  • creating withdrawl proofs

Getting started

Installation

pip install optimism-python

Deposit ETH to L2

from web3 import Web3
from optimism import CrossChainMessenger
from optimism.types import Chains

# Create a node provider for each chain
provider_l1 = Web3(Web3.HTTPProvider("https://eth-mainnet.g.alchemy.com/v2/<your-alchemy-key>"))
provider_l2 = Web3(Web3.HTTPProvider("https://optimism-mainnet.g.alchemy.com/v2/<your-alchemy-key>"))

# Specify an account for each chain (can be the same)
account_l1 = provider_l1.eth.account.from_key("<your-private-key>")
account_l2 = provider_l2.eth.account.from_key("<your-private-key>")

# Create a messenger instance
messenger = CrossChainMessenger(chain_l1=Chains.ETHEREUM_MAINNET,
                                chain_l2=Chains.OPTIMISM_MAINNET,
                                account_l1=account_l1, 
                                account_l2=account_l2,
                                provider_l1=provider_l1,
                                provider_l2=provider_l2)

# Deposit 1 ETH to L2
messenger.deposit_eth(10**18)

Metadata

Release files for optimism-python 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optimism-python 0.3.1
File Size Uploaded
optimism-python-0.3.1.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for optimism-python 0.3.1
File Interpreter ABI Platform
optimism_python-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 40.3 kB

Release files / optimism-python-0.3.1.tar.gz

Download URL optimism-python-0.3.1.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f168167ee0ee29ee7fd0be29d9ab6afa17fb1c664a31ae01be5d400896e4eff0
BLAKE2b-256 checksum
How to use checksums
86be2e9613850c30e649cd4be7ac32213041cb4400e312c5b4bff7b05ad85d8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.12 Linux/6.8.0-47-generic

Release files / optimism_python-0.3.1-py3-none-any.whl

Download URL optimism_python-0.3.1-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3711da08058c3275a91cac51cc42492e9da337472d9642757bd7e61cb8817fd
BLAKE2b-256 checksum
How to use checksums
916ba33d5d935e13d13c83e3f1a05612693f6a85e0ee0fff2d017ec9675570da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.12 Linux/6.8.0-47-generic

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page