Post
Share your knowledge.
How do i switch between Testnet and Mainnet using SUI CLI?
I'm trying to understand this aspect of the Sui Network because I'm either building, debugging, or deploying something that touches this area. I want a detailed explanation of how this mechanism or feature works, along with relevant CLI usage, Move code structure, or architectural concepts. My goal is to gain enough clarity to apply this knowledge in a real project—whether that's a custom smart contract, an NFT system, a wallet integration, or a DeFi tool. The Sui Network has unique features compared to EVM chains, so I'm particularly interested in what sets it apart and how that affects development best practices. It would help to have sample code, command line examples, or typical errors to watch for, especially when using the Sui CLI, SDK, or deploying on localnet/testnet. Ultimately, I want to avoid common mistakes, follow the best security principles, and ensure that the functionality I’m working on behaves as expected under realistic conditions.
- Sui
- NFT Ecosystem
- Move
Answers
15To switch between Testnet and Mainnet using the Sui CLI, you can use the --network
flag to specify the desired network when running commands.
Key Commands:
-
Switch to Testnet:
sui client set-config --network testnet
-
Switch to Mainnet:
sui client set-config --network mainnet
This will configure the CLI to interact with either the Testnet or Mainnet, depending on your choice.
CLI Usage Example:
-
Deploying on Testnet:
sui client publish --network testnet --package <package-id>
-
Deploying on Mainnet:
sui client publish --network mainnet --package <package-id>
Best Practices:
- Ensure you're using the correct network for deployment to avoid unintentional actions on the wrong chain.
- Always test on Testnet before deploying on Mainnet to ensure correctness.
To switch between Testnet and Mainnet using the Sui CLI, you need to update your active environment using sui client switch. The Sui CLI manages environments via configuration profiles, each pointing to a different RPC endpoint.
Steps:
- List available environments:
sui client active-address
- Switch to Testnet:
sui client switch --env testnet
- Switch to Mainnet:
sui client switch --env mainnet
- Verify the environment:
sui client active-env
- If you need custom RPC URLs or want to create your own profile (e.g., for localnet), edit the ~/.sui/sui_config/client.yaml file or use:
sui client new-env --alias localnet --rpc http://127.0.0.1:9000
Notes:
Make sure your wallet is funded on the network you’re working with.
Testnet and Mainnet addresses are separate; tokens or objects do not carry over.
Be cautious not to deploy test code to Mainnet without full audit and testing.
This approach allows clean switching between environments for debugging, deploying, and interacting with smart contracts or other assets under realistic test conditions.
To switch between Testnet and Mainnet in the Sui CLI, use the sui client switch
command followed by the desired environment (e.g., sui client switch --env mainnet
). Alternatively, manually configure the RPC endpoint in client.yaml
or via sui client new-env
to define custom networks. Unlike EVM chains where network switching often relies on provider URLs, Sui’s CLI maintains explicit environment profiles, reducing accidental cross-network deployments. Always verify your active network with sui client active-env
before executing transactions to avoid testnet/mainnet confusion.
To switch between Testnet and Mainnet using the Sui CLI, you need to change the active RPC endpoint in your Sui client configuration. You do this by using the sui client switch
command along with a specified environment like testnet
, mainnet
, or a custom URL. If you installed Sui CLI properly, you can quickly switch to the Testnet by running sui client switch --env testnet
, or to the Mainnet using sui client switch --env mainnet
. This changes the RPC endpoint your local CLI connects to, which affects all subsequent transactions, queries, or deployments. You can also use a custom endpoint if you're running a fullnode or want to target a specific public node by using --rpc <your_rpc_url>
. To confirm your current setup, you can run sui client active-address
and sui client envs
to see the current environment settings. Switching networks is essential when deploying Move packages, testing smart contracts, or querying live data on different chains. Always double-check the network before submitting real transactions to avoid loss of funds or deploying test code to production.
To switch between Testnet and Mainnet in the SUI CLI, you need to set the appropriate network for your commands. This is done by specifying the network URL or using a configuration file. Here's how to do it:
Switching Between Testnet and Mainnet Using SUI CLI
- Set Network for SUI CLI:
The
sui
CLI uses environment variables to determine the network. You can switch between Testnet and Mainnet by setting the environment variable for theSUI_ENV
network or using the--network
flag in your commands.
Option 1: Set via Environment Variable
You can set the SUI_ENV
environment variable to either testnet
or mainnet
.
-
For Testnet:
export SUI_ENV=testnet
-
For Mainnet:
export SUI_ENV=mainnet
Once the environment variable is set, the SUI CLI will use the corresponding network for all subsequent commands.
Option 2: Set via Command Line Flag (--network
)
For each command, you can specify the network using the --network
flag:
-
For Testnet:
sui client <command> --network testnet
-
For Mainnet:
sui client <command> --network mainnet
Example Command:
To publish a package on Testnet:
sui client publish --gas-budget 10000 --network testnet
To publish a package on Mainnet:
sui client publish --gas-budget 10000 --network mainnet
Common Errors to Watch For:
- Incorrect Network: If you try to interact with the wrong network, your transactions may fail or be sent to the wrong chain.
- Configuration Issues: Ensure the
SUI_ENV
environment variable is set correctly or that you're using the right flag for each command.
Best Practices:
- Environment-Specific Configuration: Set the network environment variable at the start of your session to avoid having to specify
--network
for every command. - Test Before Mainnet: Always test your contract or transaction on Testnet before deploying to Mainnet.
By following these steps, you can easily switch between Testnet and Mainnet in the SUI CLI to interact with the appropriate environment for your development or production needs.
To switch between Testnet and Mainnet using the Sui CLI, you need to update the active environment profile that your CLI uses to interact with the Sui network. You do this by specifying a --env
flag in commands or by setting the environment using the configuration profile. Sui CLI supports predefined environments like testnet
, mainnet
, and localnet
.
If you want to switch permanently, use the following command:
sui client switch --env testnet
or
sui client switch --env mainnet
This changes the default fullnode URL and configuration in your CLI profile. You can also verify or edit your CLI settings by checking the ~/.sui/sui_config/sui_client.yaml
file. This is where endpoint URLs, active addresses, and keypairs are stored.
Alternatively, you can override the endpoint temporarily without switching the profile using:
sui client call --url https://fullnode.testnet.sui.io:443
or for Mainnet:
sui client call --url https://fullnode.mainnet.sui.io:443
Make sure your wallet or keypair has assets on the corresponding network, as each environment maintains its own state and assets. Also, avoid using Testnet keys or addresses on Mainnet for security and data separation.
To switch between Testnet and Mainnet in the Sui CLI, update your active network configuration using the sui client switch
command:
# Switch to testnet
sui client switch --network testnet
# Switch to mainnet
sui client switch --network mainnet
# Check current network
sui client active-address
The CLI uses predefined network endpoints (testnet: https://fullnode.testnet.sui.io:443
, mainnet: https://fullnode.mainnet.sui.io:443
). Configuration is stored in ~/.sui/sui-config/client.yaml
.
Critical considerations:
- Use separate wallets/addresses for testnet vs mainnet
- Testnet SUI has no value; obtain via faucet:
sui client faucet-request
- Mainnet requires real SUI for gas (use trusted exchange or wallet)
- Always verify network before signing transactions
- Move packages published on one network are not automatically available on another
This network isolation ensures security and prevents accidental mainnet deployments during development.
Switch between Testnet and Mainnet in Sui CLI by changing the active environment:
1. List Available Networks
sui client envs
2. Switch to Testnet or Mainnet
# Switch to Testnet
sui client switch --env testnet
# Switch to Mainnet
sui client switch --env mainnet
3. Verify Current Network
sui client active-env
Key Notes
- RPC Endpoints:
- Testnet:
https://fullnode.testnet.sui.io
- Mainnet:
https://fullnode.mainnet.sui.io
- Testnet:
- Local Config: Stored in
~/.sui/sui_config/client.yaml
.
Common Pitfalls
- Mismatched Addresses: Testnet/Mainnet addresses differ.
- Gas Budgets: Mainnet requires higher gas budgets than Testnet.
Use sui client switch
to change networks:
-
List Networks
sui client envs
-
Switch
sui client switch --env mainnet # or testnet
Key Notes:
✔ Config stored in ~/.sui/sui_config/client.yaml
.
✔ Each network has separate addresses/keys.
Alternative: Manually set RPC URL:
sui client --rpc-url https://fullnode.mainnet.sui.io
(Unlike EVM chains, Sui CLI manages networks as named environments.)
To switch between Testnet and Mainnet in Sui CLI, use the sui client switch command. This command updates the active environment to either testnet, mainnet, or another configured endpoint. First, make sure you have installed the Sui CLI and initialized your wallet using sui client init. To switch to testnet, run sui client switch --env testnet. To switch to mainnet, use sui client switch --env mainnet. You can confirm your current environment by running sui client active-env. Each network has separate addresses and object states, so assets on testnet do not appear on mainnet. You can also define a custom environment using sui client new-env --alias
To switch between Testnet and Mainnet using the Sui CLI, you modify the active environment profile in your CLI configuration. The Sui CLI uses a sui_config/sui_config.yaml file to manage connections to different networks. This file holds multiple environments (Mainnet, Testnet, Devnet, and Localnet), and you can switch between them as needed.
Steps to Switch Network:
- View Current Active Environment:
sui client active-env
- List Available Environments:
sui client envs
- Switch to Testnet:
sui client switch --env testnet
- Switch to Mainnet:
sui client switch --env mainnet
- Optional: Add a Custom RPC Endpoint (if needed):
sui client new-env --alias customnet --rpc https://fullnode.custom.sui.io:443 sui client switch --env customnet
Architecture Concept:
Each environment uses a separate RPC URL to talk to the Sui network. Mainnet and Testnet have different object states, packages, and coin values. Smart contracts deployed on Testnet will not exist on Mainnet unless you explicitly deploy them again.
Move Development Consideration:
When writing or testing Move code, you usually deploy it with:
sui client publish --gas-budget 100000000
Make sure you're connected to the correct environment before publishing or interacting with packages.
Common Mistakes:
Forgetting to switch environments and publishing to the wrong network.
Using testnet faucet or coins on mainnet where they’re invalid.
Assuming package addresses are the same across networks—they are not.
Best Practice:
Always confirm the active network before performing actions:
sui client active-env
Keep a separate sui_config.yaml backup for each network if you're managing multiple projects. This ensures you avoid deploying or calling contracts on the wrong chain.
To switch between Testnet and Mainnet using the Sui CLI, you use the sui client switch command. The CLI stores environment profiles in your ~/.sui/sui_config.yaml file. To check your current environment, run:
sui client active-env
To list all configured environments, use:
sui client envs
To switch to Testnet:
sui client switch --env testnet
To switch to Mainnet:
sui client switch --env mainnet
If you're missing an environment, you can add one using:
sui client new-env --alias customnet --rpc https://fullnode.testnet.sui.io:443
Always verify your environment before deploying or interacting with smart contracts.
To switch between Testnet and Mainnet using the Sui CLI, you just change the active environment profile, which tells the CLI which RPC URL and network settings to use. Sui CLI supports multiple environments like testnet
, mainnet
, devnet
, and localnet
, and each one has a different RPC and faucet configuration stored in your Sui config file.
You can view your current profile by running:
sui client active-env
To switch to Testnet:
sui client switch --env testnet
To switch to Mainnet:
sui client switch --env mainnet
If you haven’t set them up before, the CLI will automatically fetch the correct RPC URLs and network settings from Sui’s default config endpoints. After switching, all your commands like publishing, transferring, and querying will point to that selected network.
Each profile has its own wallet and key storage, so if you’ve funded your address on Testnet, it won’t automatically carry over to Mainnet—you’ll need a separate wallet or import your keys manually if needed.
What makes this different from EVM chains is that Sui treats environments more like separate profiles instead of just different RPC endpoints. This means the CLI abstracts the RPC selection for you, making network switching smoother but requiring awareness of which environment your wallet and package IDs belong to.
Common mistakes include trying to use a Testnet object on Mainnet (IDs won’t exist), not switching before deploying or funding, or using the wrong gas budget since fees differ slightly across networks.
1. CLI Network Switching
List Available Networks
sui client envs
Example Output:
Active Environment: testnet
Available Environments:
1. mainnet
2. testnet
3. devnet
4. localnet
Switch Networks
# To Mainnet
sui client switch --env mainnet
# To Testnet
sui client switch --env testnet
# Verify current network
sui client active-address
Custom RPC Endpoints
sui client new-env \
--alias custom-mainnet \
--rpc https://fullnode.mainnet.sui.io:443
2. Move Code Considerations
Network-Specific Constants
module my_pkg::config {
const MAINNET: bool = true; // Compile-time flag
public fun get_chain_id(): u64 {
if (MAINNET) 1 else 2 // 1=Mainnet, 2=Testnet
}
}
Conditional Compilation
# Build for Mainnet
sui move build --features mainnet
# Build for Testnet
sui move build --features testnet
3. Key Architectural Differences
Aspect | Mainnet | Testnet |
---|---|---|
Gas Costs | Higher (real SUI) | Lower (test SUI) |
Upgrade Policies | Strict governance | Flexible |
Persistence | Permanent | Periodic wipes |
4. Wallet Management
Separate Accounts per Network
# Generate Testnet-specific keypair
sui client new-address testnet-ed25519
# Fund with Testnet SUI
sui client faucet --address 0xYOUR_TESTNET_ADDRESS
Export/Import Keys
# Export Mainnet key
sui client export-address mainnet-address
# Import to Testnet
sui client import-key mainnet-key.json --env testnet
5. Deployment Workflows
Testnet First
sui client publish --gas-budget 50000000 --env testnet
Mainnet Promotion
sui client publish --gas-budget 100000000 --env mainnet
6. Error Handling
Common Issues
Error | Solution |
---|---|
EWrongNetwork | Verify active env with sui client active-address |
EInsufficientGas | Fund address with faucet (Testnet) or exchange (Mainnet) |
EVersionMismatch | Ensure CLI version matches network (sui upgrade ) |
Network Checks
#[test_only]
module test {
fun test_network() {
let chain_id = config::get_chain_id();
assert!(chain_id == 1, 0); // Fail if not Mainnet
}
}
7. Security Best Practices
- Separate Keys: Never reuse Testnet keys on Mainnet
- Dry Runs: Always test with
--dry-run
first - Gas Budgets: Mainnet requires 5-10x higher budgets
8. Monitoring Tools
Network-Specific Explorers
- Mainnet: Suiscan Mainnet
- Testnet: Sui Explorer Testnet
CLI Monitoring
# Watch Mainnet sync status
watch -n 1 'sui client --env mainnet call \
--package 0x3 --module sui_system --function get_metrics'
9. Localnet Fallback
For critical testing without network dependencies:
sui-test-validator --reset
sui client switch --env localnet
Key Differentiators from EVM
Feature | Sui | EVM |
---|---|---|
Network Switching | CLI-managed environments | Manual RPC URL changes |
Gas Token | SUI (native) | ETH/other (contract-based) |
Persistence | Testnet wipes expected | Testnets usually persistent |
For production deployments:
- Test thoroughly on Testnet
- Monitor Sui Status Page
- Use CI/CD to enforce network checks
To switch between Testnet and Mainnet using the Sui CLI, you can specify the network when starting or interacting with the Sui node. Here's how you can switch between the two networks:
1. Starting the Node on Testnet or Mainnet
When you start a Sui node using the CLI, you can specify the network by using the --network
flag.
-
For Testnet:
sui node start --network testnet
-
For Mainnet:
sui node start --network mainnet
This command will start the Sui node on the corresponding network.
2. Switching Networks for RPC Interactions
If you want to interact with Testnet or Mainnet RPC servers using the Sui CLI, you need to set the appropriate endpoint for the network you want to connect to.
-
For Testnet: To interact with the testnet, you can set the RPC endpoint as
https://fullnode.testnet.sui.io:443
.Example command:
sui client --url https://fullnode.testnet.sui.io:443
-
For Mainnet: To interact with the mainnet, you can set the RPC endpoint as
https://fullnode.mainnet.sui.io:443
.Example command:
sui client --url https://fullnode.mainnet.sui.io:443
You can also set this as your default for the current session.
3. Changing Default Network (Persistent Setting)
To change the default network configuration in a persistent way, you can modify the configuration file for the Sui CLI:
- Open the Sui CLI config file (
~/.sui/config.toml
on Linux/macOS orC:\Users\<username>\AppData\Local\sui\config.toml
on Windows). - Look for the
network
orrpc
section. - Update the
rpc
endpoint and the network name to the appropriate value (Testnet or Mainnet).
For example, to use Testnet:
[network]
rpc = "https://fullnode.testnet.sui.io:443"
To use Mainnet:
[network]
rpc = "https://fullnode.mainnet.sui.io:443"
4. Verifying the Network Connection
You can verify the connection to the desired network by using the following command to check the current state of the network:
sui client --url https://fullnode.testnet.sui.io:443 status
Or for Mainnet:
sui client --url https://fullnode.mainnet.sui.io:443 status
This will return details about the connected network, which will help you confirm that you're on the correct network.
Conclusion
Switching between Testnet and Mainnet in the Sui CLI is straightforward using the --network
flag when starting the node, or by specifying the correct RPC endpoint for your commands. You can also modify the configuration file to set a persistent network for your CLI session.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- Why does BCS require exact field order for deserialization when Move structs have named fields?53
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution43
- Sui Transaction Failing: Objects Reserved for Another Transaction25
- How do ability constraints interact with dynamic fields in heterogeneous collections?05