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

chore: add spawn single node example #2739

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions ant-node/examples/spawn_node.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2025 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use ant_node::spawn::node_spawner::NodeSpawner;
use autonomi::Multiaddr;
use std::str::FromStr;

#[tokio::main]
async fn main() {
// Using the genesis node as a bootstrap node for example
let bootstrap_peers = vec![
Multiaddr::from_str("/ip4/209.97.181.193/udp/57402/quic-v1/p2p/12D3KooWHygG9a7inESky2KpvHQmbX5o2UC8D29B5njdshAcv1p6")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the multiaddr of a node from the current PROD? Do you think it would be better to do PeersArg::get_bootstrap_addr(None, 1) here? It would fetch a peer from the live PROD network. So no worries of the hardcoded ip/node going down.

.expect("Invalid multiaddr")
];

let running_node = NodeSpawner::new()
.with_initial_peers(bootstrap_peers)
.spawn()
.await
.expect("Failed to spawn node");

let listen_addrs = running_node
.get_listen_addrs_with_peer_id()
.await
.expect("Failed to get listen addrs with peer id");

println!("Node started with listen addrs: {listen_addrs:?}");
}
Loading