Post
Share your knowledge.

How to Publish Raw Bytecode to SUI Localnet
Deploying smart contracts on the SUI blockchain typically involves compiling Move code into bytecode and publishing it to the network. While the SUI CLI automates much of this process, developers occasionally seek guidance on manually handling raw bytecode, especially in local testing environments like Localnet. This article walks through the steps to publish raw bytecode to SUI Localnet, leveraging the SUI CLI and development tools.
Prerequisites on SUI Localnet
Before diving into deployment, ensure you have the following:
- SUI CLI Installed: Follow the official installation guide to set up the
sui
command-line tool. - Localnet Running: Use the
sui-test-validator
binary to launch a local SUI network for testing (https://docs.sui.io/). - Move Package: A functional Move package with modules and dependencies configured.
What's SUI Localnet
SUI Localnet is a sandboxed environment for testing smart contracts without risking real assets. It allows developers to simulate interactions, debug logic, and verify deployments before moving to Devnet or Mainnet. To start Localnet, run:
sui-test-validator
This initializes a local validator node, providing a fresh testing ground with pre-funded accounts (https://docs.sui.io/)(https://scaf.gitbook.io/scaf/).
How to Prepare Your Move Package?
A Move package consists of source code (sources/
), dependencies (deps/
), and build artifacts (build/
). To compile raw bytecode, focus on the build
directory, which contains .mv
files—the compiled Move bytecode.
-
Build the Package:
sui client build <package_path>
Replace
<package_path>
with the directory containing yourMove.toml
file. This generates bytecode in thebuild/
folder. -
Locate Bytecode:
Navigate tobuild/<package_name>/bytecode/
to find.mv
files for each module. These represent the raw bytecode to be published.
Publishing Raw Bytecode to Localnet
While the SUI CLI abstracts bytecode management, you can manually publish raw bytecode using the sui client publish
command. This command accepts pre-built bytecode instead of recompiling the package.
Step-by-Step Guide
-
Start Localnet:
Ensure the local validator is running:sui-test-validator
-
Publish Bytecode:
Use thepublish
command with the--bytecode
flag to specify the raw bytecode directory:sui client publish --bytecode <bytecode_path>
Replace
<bytecode_path>
with the path to yourbuild/<package_name>/bytecode/
directory.Example:
sui client publish --bytecode ./build/my_package/bytecode/
The CLI will submit the bytecode to the Localnet, creating a new package object on-chain (https://thelib.to/move-book)(https://sui.io/).
-
Verify Deployment:
Check the transaction details in the CLI output. Use the SUI Explorer (if available for Localnet) or query the package via:sui client get-package <package_id>
Typicall Error with Sui CLI
1. CLI Version Mismatches
If the CLI fails to recognize commands, update it using the recommended method for your OS. Avoid manual updates via cargo
to prevent dependency conflicts (https://discord.gg/sui).
2. Bytecode Path Errors
Ensure the --bytecode
flag points directly to the directory containing .mv
files. Incorrect paths will trigger compilation errors.
3. Localnet Connection Failures
Confirm the sui-test-validator
is active and that your CLI configuration points to Localnet. Use:
sui client envs
to verify the active environment (https://docs.sui.io/).
Conclusion
Publishing raw bytecode to SUI Localnet is a basic process when using the SUI CLI’s publish
command with the --bytecode
flag. By leveraging Localnet’s isolated environment, developers can iteratively test contracts without incurring costs or risks. While manual bytecode manipulation is possible, the platform’s design prioritizes automation, ensuring reliability and simplicity for most use cases.
- Sui
- SDKs and Developer Tools
- Move
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