Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Add Infura API key env var intructions (#879)
Browse files Browse the repository at this point in the history
* Add Infura API key env var intructions

* Update dotenv call
  • Loading branch information
matias-gonz authored Aug 1, 2023
1 parent 4bd008e commit 51ec5a8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ target/

# END AUTOGENERATED

.env
cairo1
cairo2
starknet-venv/
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ $ make build
```
Check the [Makefile](/Makefile) for additional targets.

#### RPC State Reader

In order to use the RPC state reader add an Infura API key in a `.env` file at root:

```
INFURA_API_KEY={some_key}
```

#### How to manually install the script dependencies

`cairo-lang` requires the `gmp` library to build.
Expand Down Expand Up @@ -94,6 +102,8 @@ You can find an example on how to use the CLI [here](/docs/CLI_USAGE_EXAMPLE.md)

### Testing

[Add an Infura API key.](#rpc-state-reader)

Run the following command:
```bash
$ make test
Expand Down
1 change: 1 addition & 0 deletions rpc_state_reader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ cairo-lang-starknet = "2.1.0-rc2"
starknet = { workspace = true }
thiserror = { workspace = true }
serde_with = "3.0.0"
dotenv = "0.15.0"
4 changes: 4 additions & 0 deletions rpc_state_reader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::fmt;
use dotenv::dotenv;
use serde::{Deserialize, Deserializer};
use serde_json::json;
use serde_with::{serde_as, DeserializeAs};
Expand Down Expand Up @@ -106,6 +107,9 @@ struct RpcResponseFelt252 {

impl RpcState {
pub fn new(chain: RpcChain, block: BlockValue) -> Self {
if env::var("INFURA_API_KEY").is_err() {
dotenv().expect("Missing .env file");
}
Self {
chain,
api_key: env::var("INFURA_API_KEY")
Expand Down

0 comments on commit 51ec5a8

Please # to comment.