Streamlit components and helpers for browser-injected EIP-1193 provider utility.
Project description
streamlit-web3
streamlit-web3 packages a hidden Streamlit component that bridges a browser-injected EIP-1193 wallet provider into
Web3.py.
Install
pip install streamlit-web3
Minimal usage
import streamlit as st
from streamlit_browser_web3 import wallet_get
handler = wallet_get()
if handler.status == "connected":
if st.button("Disconnect your wallet"):
handler.disconnect()
page_body(handler)
else:
if st.button("Connect your wallet"):
handler.connect()
Important Streamlit behavior
Wallet operations are asynchronous in the browser but Streamlit scripts are synchronous and rerun-driven.
wallet_get()must be rendered on every rerun.- A wallet request may complete over multiple reruns.
- For button-triggered Web3 calls, persist the user intent in
st.session_stateuntil the call returns. - Requests are serialized through the hidden browser bridge.
Chain metadata and ERC-20 helper code are intentionally kept in the example app, not in the package.
Handler API
wallet_get() returns a WalletHandler instance. Render it on every rerun and use the same handler object as your app's wallet state interface.
State properties
handler.status: One of"not-available","disconnected", or"connected".handler.available:Truewhen an injected browser provider such aswindow.ethereumexists.handler.connected:Truewhen the wallet is connected and at least one account is available.handler.accounts: List of currently exposed account addresses.handler.chain_id: Current chain id as anint, orNone.handler.chain_id_hex: Current chain id as a hex string such as"0x1", orNone.handler.busy:Truewhile a connect/disconnect action or an interactive wallet request is still pending.handler.last_error: Last wallet or bridge error message, if any.handler.snapshot: Raw snapshot dictionary returned by the hidden browser component.
Methods
handler.connect(): Starts the wallet connection flow and reruns the Streamlit script.handler.disconnect(): Starts the wallet disconnect flow and reruns the Streamlit script.handler.request(method, params=None, *, key): Sends an EIP-1193 request and returns(status, result).handler.get_request_status(key): Returns the current status of a given request, orNoneif it does not exist.handler.forget(key): Removes a tracked request so the same key can be reused for a new flow.handler.snapshot_view(): Returns a typedWalletSnapshotdataclass with the main handler fields.
request() status values
handler.request(...) returns a (status, result) tuple:
"pending": The wallet request is still waiting for completion in the browser."success": The request completed successfully andresultcontains the returned value."error": The request failed andresultcontains an error message.
The key argument is required. Requests are tracked by key across reruns, which lets button-triggered flows continue until the browser returns a result.
Supported request methods
The handler has built-in support for these immediate methods, which resolve from the current snapshot without opening a wallet prompt:
eth_accountseth_chainIdeth_coinbasenet_version
The handler also marks these methods as interactive, meaning they can leave handler.busy == True while the wallet is waiting for user confirmation:
eth_requestAccountseth_sendTransactioneth_signeth_signTransactioneth_signTypedDataeth_signTypedData_v1eth_signTypedData_v3eth_signTypedData_v4personal_signwallet_addEthereumChainwallet_requestPermissionswallet_revokePermissionswallet_switchEthereumChain
Other provider methods can still be passed to handler.request(...). They are tracked as non-interactive requests unless they are in the interactive list above.
Build
python -m build
Example app
An end-to-end example is included at examples/streamlit_app.py.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file streamlit_browser_web3-0.2.0.tar.gz.
File metadata
- Download URL: streamlit_browser_web3-0.2.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1c1a37a1aa729b83c4e0591132b163c8fd7bdd286734c58db0e16f0094c370c
|
|
| MD5 |
6a159280295a6c91ba1671a913d66caa
|
|
| BLAKE2b-256 |
156ba1093dcb4e1cc0208a768a7e2906d986759cd19fdfa3e7c2336d2c330a9d
|