Skip to content

Commit

Permalink
docs(autonomi): improve example code
Browse files Browse the repository at this point in the history
  • Loading branch information
b-zee committed Dec 4, 2024
1 parent 569364f commit cf613d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions autonomi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ cargo add autonomi
### Example

```rust
use autonomi::{Bytes, Client, EvmNetwork, Wallet};
use autonomi::{Bytes, Client, Wallet};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Default wallet of testnet.
let key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";

let client = Client::connect(&["/ip4/127.0.0.1/udp/1234/quic-v1".parse()?]).await?;
let wallet = Wallet::new_from_private_key(EvmNetwork::ArbitrumSepolia, key)?;
let wallet = Wallet::new_from_private_key(Default::default(), key)?;

// Put and fetch data.
let data_addr = client
Expand All @@ -43,6 +43,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```

In the above example the wallet is setup to use the default EVM network (Arbitrum One). Instead we can use a different network:
```rust
use autonomi::{EvmNetwork, Wallet};
// Arbitrum Sepolia
let wallet = Wallet::new_from_private_key(EvmNetwork::ArbitrumSepolia, key)?;
// Custom (e.g. local testnet)
let wallet = Wallet::new_from_private_key(EvmNetwork::new_custom("<rpc URL>", "<payment token address>", "<data payment address>"), key)?;
```

## Running tests

### Using a local EVM testnet
Expand Down
4 changes: 2 additions & 2 deletions autonomi/examples/put_and_dir_upload.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use autonomi::{Bytes, Client, EvmNetwork, Wallet};
use autonomi::{Bytes, Client, Wallet};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Default wallet of testnet.
let key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";

let client = Client::connect(&["/ip4/127.0.0.1/udp/1234/quic-v1".parse()?]).await?;
let wallet = Wallet::new_from_private_key(EvmNetwork::ArbitrumSepolia, key)?;
let wallet = Wallet::new_from_private_key(Default::default(), key)?;

// Put and fetch data.
let data_addr = client
Expand Down

0 comments on commit cf613d3

Please sign in to comment.