Skip to content

Commit

Permalink
feat: missing ws
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 5, 2024
1 parent 7ca7de9 commit a7806ec
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,30 @@
# Alchemy will try to publish private transactions for 25 blocks.
PRIVATE_TX_BLOCK_WAIT = 25

NETWORKS_SUPPORTING_WEBSOCKETS = ("ethereum", "arbitrum", "base", "optimism", "polygon", "fantom")
# NOTE: "*" means "all networks".
NETWORKS_SUPPORTING_WEBSOCKETS = {
"abstract": "*",
"arbitrum": "*",
"avalanche": "*",
"base": "*",
"bsc": ("mainnet", "testnet"),
"berachain": "*",
"blast": "*",
"ethereum": "*",
"fantom": "*",
"geist": ("polter",),
"gnosis": "*",
"lens": "*",
"linea": "*",
"optimism": "*",
"polygon": "*",
"scroll": "*",
"shape": "*",
"soneium": "*",
"unichain": "*",
"world-chain": "*",
"zksync": "*",
}


class Alchemy(Web3Provider, UpstreamProvider):
Expand Down Expand Up @@ -119,7 +142,13 @@ def http_uri(self) -> str:
return self.uri

@property
def ws_uri(self) -> str:
def ws_uri(self) -> Optional[str]:
ecosystem_name = self.network.ecosystem.name
network_name = self.network.name
supported_networks = NETWORKS_SUPPORTING_WEBSOCKETS.get(ecosystem_name, [])
if supported_networks != "*" and network_name not in supported_networks:
return None

# NOTE: Overriding `Web3Provider.ws_uri` implementation
return "ws" + self.uri[4:] # Remove `http` in default URI w/ `ws`

Expand Down

0 comments on commit a7806ec

Please sign in to comment.