Skip to content

Commit adf3de1

Browse files
committed
sdk: update README.md example
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 2576ce7 commit adf3de1

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

crates/nostr-sdk/README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,26 @@ async fn main() -> Result<()> {
4343
let bech32_pubkey: String = my_keys.public_key().to_bech32()?;
4444
println!("Bech32 PubKey: {}", bech32_pubkey);
4545
46-
// Create new client
47-
let client = Client::new(&my_keys);
48-
49-
let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
46+
// Configure client to use proxy for `.onion` relays
47+
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050));
48+
let connection: Connection = Connection::new()
49+
.proxy(addr) // Use `.embedded_tor()` instead to enable the embedded tor client (require `tor` feature)
50+
.target(ConnectionTarget::Onion);
51+
let opts = Options::new().connection(connection);
52+
53+
// Create new client with custom options.
54+
// Use `Client::new(signer)` to construct the client with a custom signer and default options
55+
// or `Client::default()` to create one without signer and with default options.
56+
let client = Client::with_opts(&my_keys, opts);
5057
5158
// Add relays
5259
client.add_relay("wss://relay.damus.io").await?;
60+
client.add_relay("ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion").await?;
61+
62+
// Add relay with custom options
5363
client.add_relay_with_opts(
5464
"wss://relay.nostr.info",
55-
RelayOptions::new().proxy(proxy).write(false)
56-
).await?;
57-
client.add_relay_with_opts(
58-
"ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion",
59-
RelayOptions::new().proxy(proxy),
65+
RelayOptions::new().write(false)
6066
).await?;
6167
6268
// Connect to relays

0 commit comments

Comments
 (0)