Connect to a Local Network
Use a Sui local network to test your dApps against the latest changes to Sui, and to prepare for the next Sui release to Devnet or Testnet. Sui CLI provides the sui start
command to start a local network. There are several services that can be started when using sui start
, such as an indexer, a faucet, or a local instance of the GraphQL service (including the web-based GraphiQL IDE). You can use the included faucet to get test SUI to use on the local network.
If you haven't already, you need to install Sui CLI on your system.
Start the local network
To start the local network, run the following command after you install Sui CLI.
$ RUST_LOG="off,sui_node=info" sui start --with-faucet --force-regenesis
This command:
- Calls the Sui CLI binary with two flags:
--with-faucet
to start a faucet service.--force-regenesis
to generate a new genesis and not persist the local network state.- Instructs Rust to set specific logging through the
RUST_LOG
=off,sui_node=info
flags, which turns off logging for all components exceptsui-node
. If you want to see more detailed logs, you can removeRUST_LOG
from the command.
Each time you start the network by passing --force-regenesis
, the local network starts from a random genesis with no previous data, and the local network is not persisted. If you'd like to persist data, skip passing the --force-regenesis
flag. For more details, see the Persist local network state section. Please note that a temporary directory is created in /tmp
, which might not work if the /tmp
folder is mounted to /tmpfs
. If this is the case, set TMPDIR=./some_folder
.
To customize your local Sui network, such as starting other services or changing default ports and hosts, include additional flags or options in the sui start
command.
Options and flags like with-indexer
, with-graphql
, and related require you to have PostgreSQL/libpq installed. Check out the list of possible options below to find which is the default expected DB, or how to pass a different DB.
The following is a list of possible options and flags to pass to sui start
:
--network.config <CONFIG_DIR> Config directory that will be used to store network config, node db, Keystore sui genesis -f --with-faucet generates a genesis config that can be used to start this process. Use with caution as the `-f` flag
will overwrite the existing config directory. We can use any config dir that is generated by the `sui genesis`
--force-regenesis A new genesis is created each time this flag is set, and state is not persisted between runs. Only use this flag when you want to start the network from scratch every time you run this command
--with-graphql[=<WITH_GRAPHQL>] Start a GraphQL server on localhost and port: 127.0.0.1:9125, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-graphql=6125`. Note that
GraphQL requires a running indexer
--with-faucet[=<WITH_FAUCET>] Start a faucet with default host and port: 127.0.0.1:9123, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-faucet=6123`
--with-indexer[=<WITH_INDEXER>] Start an indexer with default host and port: 0.0.0.0:9124, or on the port provided. When providing a specific value, please use the = sign between the flag and value: `--with-indexer=6124`. The indexer be started in writer mode and reader mode
--fullnode-rpc-port <FULLNODE_RPC_PORT> Port to start the Fullnode RPC server on. Default port is 9000 [default: 9000]
--pg-port <PG_PORT> Port for the Indexer Postgres DB. Default port is 5432 [default: 5432]
--pg-host <PG_HOST> Hostname for the Indexer Postgres DB. Default host is localhost [default: localhost]
--pg-db-name <PG_DB_NAME> DB name for the Indexer Postgres DB. Default DB name is sui_indexer [default: sui_indexer]
--pg-user <PG_USER> DB username for the Indexer Postgres DB. Default username is postgres [default: postgres]
--pg-password <PG_PASSWORD> DB password for the Indexer Postgres DB. Default password is postgrespw [default: postgrespw]
--epoch-duration-ms <EPOCH_DURATION_MS> Set the epoch duration. Can only be used when `--force-regenesis` flag is passed or if there's no genesis config and one will be auto-generated. When this flag is not set but `--force-regenesis` is set, the
epoch duration will be set to 60 seconds
--no-full-node Start the network without a fullnode
-h, --help Print help (see more with '--help')
Use sui start --help
to see these options in your console.
Persist local network state
By default, when using sui start
the command uses an existing genesis and network configuration if the ~/.sui/sui_config
folder exists and includes a genesis.blob
file. If the folder doesn't exist, it creates the folder and generates a new genesis configuration. If you pass --network.config
, the command checks for the network config file and tries to load the genesis blob as per the network config file.
Whenever you stop and start the network without passing the --force-regenesis
flag, all history is preserved and accessible.
To generate a custom genesis, use the sui genesis
command and pass the desired custom values. For more information about possible flags and options, run sui genesis --help
.
Access your local full node
Use the following command to retrieve the total transaction count from your local network:
$ curl --location --request POST 'http://127.0.0.1:9000' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"id": 1,
"method": "sui_getTotalTransactionBlocks",
"params": []
}'
If successful, the response resembles the following:
{
"jsonrpc": "2.0",
"result": 168,
"id": 1
}