Running 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::{
            fuel_node::{Config, FuelService},

        // Run the fuel node.
        let server = FuelService::new_node(Config::local_node())
            .map_err(|err| error!(InfrastructureError, "{err}"))?;

        // Create a client that will talk to the node created above.
        let client = FuelClient::from(server.bound_address);

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;


Fuel-core lib

The fuel-core-lib is a feature defined in the fuels library, allowing 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.37.1", features = ["fuel-core-lib"] }