Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure dotenv #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
STYLUS_PROGRAM_ADDRESS=<the onchain address of your deployed program>
PRIV_KEY_PATH=<the file path for your priv key to transact with>
RPC_URL=https://stylus-testnet.arbitrum.io/rpc
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.env
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ alloy-sol-types = "0.3.1"
stylus-sdk = "0.3.0"
hex = "0.4.3"
wee_alloc = "0.4.5"
dotenv = "0.15.0"

[dev-dependencies]
tokio = { version = "1.12.0", features = ["full"] }
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ let num = counter.number().call().await;
println!("New counter number value = {:?}", num);
```

To run it, set the following env vars or place them in a `.env` file this project, then:
To run it, set your env vars or in a `.env` file:
```bash
cp .env.example .env
```

Now update `.env`:
```
STYLUS_PROGRAM_ADDRESS=<the onchain address of your deployed program>
PRIV_KEY_PATH=<the file path for your priv key to transact with>
Expand Down
6 changes: 5 additions & 1 deletion examples/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Then, it attempts to check the current counter value, increment it via a tx,
//! and check the value again. The deployed program is fully written in Rust and compiled to WASM
//! but with Stylus, it is accessible just as a normal Solidity smart contract is via an ABI.
use dotenv::dotenv;
use ethers::{
middleware::SignerMiddleware,
prelude::abigen,
Expand All @@ -24,7 +25,10 @@ const ENV_PROGRAM_ADDRESS: &str = "STYLUS_PROGRAM_ADDRESS";

#[tokio::main]
async fn main() -> eyre::Result<()> {
let priv_key_path = std::env::var(ENV_PRIV_KEY_PATH)
// Read env vars from .env file
dotenv().ok();

let priv_key_path = std::eanv::var(ENV_PRIV_KEY_PATH)
.map_err(|_| eyre!("No {} env var set", ENV_PRIV_KEY_PATH))?;
let rpc_url =
std::env::var(ENV_RPC_URL).map_err(|_| eyre!("No {} env var set", ENV_RPC_URL))?;
Expand Down