diff --git a/.gitignore b/.gitignore index ab29945f4..a3eca4013 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ target/ # END AUTOGENERATED +.env cairo1 cairo2 starknet-venv/ diff --git a/Cargo.lock b/Cargo.lock index 4880d938f..a34b327d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1525,6 +1525,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dyn-clone" version = "1.0.12" @@ -2928,6 +2934,7 @@ name = "rpc_state_reader" version = "0.3.0" dependencies = [ "cairo-lang-starknet", + "dotenv", "serde", "serde_json", "serde_with 3.1.0", diff --git a/README.md b/README.md index fc7e4b6c6..8ba5f0b49 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/rpc_state_reader/Cargo.toml b/rpc_state_reader/Cargo.toml index 484dbe0d5..4b96e620e 100644 --- a/rpc_state_reader/Cargo.toml +++ b/rpc_state_reader/Cargo.toml @@ -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" diff --git a/rpc_state_reader/src/lib.rs b/rpc_state_reader/src/lib.rs index 5f2b40401..f8a65a667 100644 --- a/rpc_state_reader/src/lib.rs +++ b/rpc_state_reader/src/lib.rs @@ -1,4 +1,5 @@ use core::fmt; +use dotenv::dotenv; use serde::{Deserialize, Deserializer}; use serde_json::json; use serde_with::{serde_as, DeserializeAs}; @@ -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")