Icon SunFilledIcon MoonStars

Icon LinkCustom chain

This example demonstrates how to start a short-lived Fuel node with custom consensus parameters for the underlying chain.

First, we have to import ConsensusParameters and ChainConfig:

use fuels::{fuel_node::ChainConfig, prelude::*, tx::ConsensusParameters};

Next, we can define some values for the consensus parameters:

let consensus_parameters_config = ConsensusParameters::DEFAULT
    .with_max_gas_per_tx(1000)
    .with_gas_price_factor(10)
    .with_max_inputs(2);
let chain_config = ChainConfig {
    transaction_parameters: consensus_parameters_config,
    ..ChainConfig::default()
};

Before we can start a node, we probably also want to define some genesis coins and assign them to an address:

let wallet = WalletUnlocked::new_random(None);
let coins = setup_single_asset_coins(
    wallet.address(),
    Default::default(),
    DEFAULT_NUM_COINS,
    DEFAULT_COIN_AMOUNT,
);

Finally, we call setup_test_provider(), which starts a node with the given configs and returns a provider attached to that node:

let node_config = Config::local_node();
let (_provider, _bound_address) =
    setup_test_provider(coins, vec![], Some(node_config), Some(chain_config)).await;

Was this page helpful?