Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit 43dc91f

Browse files
committed
wip
1 parent 0e49149 commit 43dc91f

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,41 @@ pip3 install alchemy_sdk_py
1818
## Quickstart
1919

2020
### Get an API Key
21-
After [installing](#installation), you'll need to sign up for an API key and set it as an `ALCHEMY_API_KEY` environment variable.
21+
After [installing](#installation), you'll need to sign up for an API key and set it as an `ALCHEMY_API_KEY` environment variable. You can place them in a `.env` file if you like *just please don't push the `.env` file to GitHub*.
22+
23+
`.env`
24+
```bash
25+
ALCHEMY_API_KEY="asdfasfsfasf
26+
```
2227
2328
If you're unfamiliar with environment variables, you can use the API to set the key directly using the SDK - please don't do this in production code.
2429
2530
```python
26-
import alchemy_sdk_py
31+
from alchemy_sdk_py import Alchemy
2732
28-
alchemy_sdk_py.set_api_key("YOUR_API_KEY")
33+
alchemy = Alchemy(api_key="asdfasfsfasf", network="eth_mainnet")
2934
```
35+
If you have your environment variable set, and you want to use eth mainnet, you can just do this:
3036
31-
This will make the key availible for the duration of your script.
37+
```python
38+
from alchemy_sdk_py import Alchemy
39+
alchemy = Alchemy()
40+
```
41+
42+
You can also set the network ID using the chainId, or hex, and even update it later.
43+
```python
44+
# For Goerli ETH
45+
alchemy = Alchemy(network=5)
46+
# For Polygon ("0x89" is hex for 137)
47+
alchemy.set_network("0x89")
48+
```
3249
3350
### Useage
3451
3552
```python
36-
import alchemy_sdk_py as alchemy
53+
from alchemy_sdk_py import Alchemy
54+
55+
alchemy = Alchemy()
3756
3857
current_block = alchemy.get_current_block()
3958
print(current_block)

alchemy_sdk_py/alchemy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,10 @@ def set_network(self, network: str):
365365
returns:
366366
None
367367
"""
368-
self.network = network
368+
self.network = Network(network)
369+
url_network_name = self.network.name.replace("_", "-")
370+
self.base_url_without_key = f"https://{url_network_name}.g.alchemy.com/v2/"
371+
self.base_url = f"{self.base_url_without_key}{self.api_key}"
369372

370373
def set_settings(self, key: Optional[str] = None, network: Optional[str] = None):
371374
"""

tests/integration/test_alchemy_functions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from alchemy_sdk_py import Alchemy
2-
import os
32

43

54
def test_set_api_key(alchemy, mock_env_missing):

0 commit comments

Comments
 (0)