Icon LinkRunning a short-lived Fuel node with the SDK

You can use the SDK to spin up a local, ideally short-lived Fuel node. Then, you can instantiate a Fuel client, pointing to this node.

use fuels::{
    client::FuelClient,
    fuel_node::{Config, FuelService},
};
 
// Run the fuel node.
let server = FuelService::new_node(Config::local_node())
    .await
    .map_err(|err| error!(InfrastructureError, "{err}"))?;
 
// Create a client that will talk to the node created above.
let client = FuelClient::from(server.bound_address);
assert!(client.health().await?);

This approach is ideal for contract testing.

You can also use the test helper setup_test_provider() for this:

use fuels::prelude::*;
 
// Use the test helper to setup a test provider.
let (provider, _address) = setup_test_provider(vec![], vec![], None, None).await;
 
// Create the wallet.
let _wallet = WalletUnlocked::new_random(Some(provider));

You can also use launch_provider_and_get_wallet(), which abstracts away the setup_test_provider() and the wallet creation, all in one single method:

let wallet = launch_provider_and_get_wallet().await;

Icon LinkFeatures

Icon LinkFuel-core lib

The fuel-core-lib feature allows us to run a fuel-core node without installing the fuel-core binary on the local machine. Using the fuel-core-lib feature flag entails downloading all the dependencies needed to run the fuel-core node.

fuels = { version = "0.46.0", features = ["fuel-core-lib"] }

Icon LinkRocksDb

The rocksdb is an additional feature that, when combined with fuel-core-lib, provides persistent storage capabilities while using fuel-core as a library.

fuels = { version = "0.46.0", features = ["rocksdb"] }
Icon ListDetailsOn this page