How to Create a Smart Contract on Sui: A Practical Guide
Create a smart contract on Sui with Move: set up the CLI, write a module, test it locally, and publish it to testnet without touching mainnet funds.
On this page
Short answer
To create a smart contract on Sui, install the Sui CLI, start a Move package with sui move new, write the logic as a module in sources, then build and test with sui move build and sui move test. When the tests pass, fund a testnet address and publish with sui client publish. The publish step returns a package ID, the address of your contract on chain.
What is a Sui smart contract?
A Sui smart contract is a Move package: a set of modules that define types and functions, published to the Sui blockchain under a package ID. Once published, anyone can call its public entry functions, and the objects it creates live on chain as data the contract and its users can read and change.
Sui differs from account-based chains in how it stores state. Everything on Sui is an object with an owner: an address, another object, or nobody at all for shared objects. A token balance, a game item, or a marketplace listing is an object, not a row in a contract's storage. This object model is what lets Sui process unrelated transactions in parallel.
Move is the language Sui contracts are written in. It is a resource-oriented language, which means values such as coins cannot be copied or dropped by accident; they must be moved, stored, or destroyed explicitly. That design catches a whole class of asset-handling bugs at compile time instead of after deployment.
| Concept | On Sui | On account-based chains |
|---|---|---|
| Contract code | Move package of modules | Contract deployed at an address |
| State | Objects with owners | Storage slots inside the contract |
| Language | Move | Usually Solidity |
| Asset safety | Resources cannot be copied or lost silently | Balances tracked by hand in code |
If you already know how Sui works as a network, the jump to writing contracts is mostly about learning Move and the object model.
What do you need before you start?
Before you start, you need the Sui CLI, a code editor, and a small amount of testnet SUI for gas. The CLI is the main tool: it creates projects, builds and tests Move code, manages addresses, and publishes packages.
Install the Sui binaries from the official Sui releases or with the package manager for your system, then run sui client once and answer its setup prompts. It creates a configuration file and asks which network to connect to; choose testnet while you are learning. Testnet SUI has no real value, so mistakes cost nothing.
Create an address with sui client new-address ed25519, then request testnet SUI from the faucet with sui client faucet. Check the balance with sui client gas. You need enough gas to pay for publishing, which is the most expensive step in the workflow, so top up before you publish rather than after a failed attempt.
You also need a clear idea of what the contract should do. A first contract should do one small thing well: a counter, a simple coin, or a registry of items. A contract that tries to be a marketplace, a token, and a governance system at once is a poor first project, and it is hard to test.
How do you set up a Sui Move project?
You set up a Sui Move project by creating a package with the CLI, which gives you a manifest file and a folder for source code. Run sui move new followed by a name in snake case, then move into the new folder.
The command creates a Move.toml manifest and a sources folder. Move.toml names the package and lists its dependencies, including the Sui framework, which provides the standard types every contract uses, such as coins and transfer functions. The sources folder holds your .move files, one per module in most small projects.
Open Move.toml and check the package name and the framework dependency. The published package address is assigned at publish time, not when you create the project, so the address in the manifest is a placeholder until then. Keep the package name short and descriptive; it shows up in error messages and in the published package.
- Run sui move new my_package and change into the new folder.
- Open Move.toml and confirm the package name and dependencies.
- Create your first module file under sources, for example my_module.move.
- Run sui move build to confirm the project compiles before writing much logic.
Build early and often. Move's compiler gives precise errors, and fixing a small error now is far easier than untangling a large module that has never compiled. A project that builds from the first module onward stays easy to work with.
How do you write your first Move module?
You write your first Move module by declaring a module, defining the data it owns as structs, and exposing entry functions that change that data. A module is a set of types and functions published together, and it is the unit of code on Sui.
Start with a struct that represents the thing your contract manages. A struct is a bundle of fields, and its abilities decide what can happen to it: a struct with the key ability can be stored as an object on chain, store lets it sit inside other structs, copy allows duplication, and drop allows it to be discarded.
A coin-like value should have key and store but not copy or drop, so it cannot be duplicated or thrown away by mistake.
Entry functions are the functions users call. Mark a function as an entry function, give it the objects it needs as parameters, and have it create, change, or transfer objects. Keep entry functions short: check the inputs, change the state, and emit the result. Long functions that mix checks, math, and transfers are hard to test.
Use the standard library instead of writing your own versions of common pieces. The Sui framework already provides coin handling, object creation, and transfers. Reusing it means your contract benefits from code that has been reviewed far more than anything you write in an afternoon. For patterns that differ by chain, compare with how contracts are created on Solana to see what Sui's object model changes.
How do you test and publish the contract?
You test and publish a Sui contract by building it, running its unit tests, funding a testnet address, and publishing with the CLI. Each step has a clear check, so a failure shows where the problem is.
Run sui move build first, and fix any compiler errors. Then run sui move test, which runs the test functions in your modules. Write tests for the happy path and for the failures: a transfer that should succeed, one that should fail, and a call with bad input.
When the tests pass, fund your testnet address from the faucet. Publishing costs gas, and the amount depends on package size, so check your balance with sui client gas first. Then run sui client publish from the package folder and save the package ID: the permanent address of your contract.
- Build with sui move build and fix any compiler errors.
- Run sui move test and add tests for every failure case you can think of.
- Fund your testnet address from the faucet and check the gas balance.
- Publish with sui client publish and record the package ID.
- Call one entry function on testnet to confirm the package works.
Do not publish to mainnet until the contract has run on testnet and, for anything holding real value, passed a security review. Testnet is where you find the bugs; mainnet is where bugs cost money. Smart contract development treats the audit as part of the build, not an afterthought.
Example (hypothetical): a loyalty token for a coffee shop
Example (hypothetical): a coffee shop wants a simple loyalty token on Sui. Each point is an object owned by the customer, and the shop's contract mints points when a purchase is recorded and burns them when a reward is claimed.
The shop expects 500 regular customers, each earning 20 points in an average month, so the contract mints about 10,000 points a month. Each point is worth one cent of discount, so the total discount value of a month's points is 10,000 times 1 cent, which is 100 dollars. If 40 percent of points are redeemed, the shop gives about 40 dollars of discounts a month.
The contract has one struct, Point, with key and store abilities, and two entry functions: mint, which only the shop's address can call, and redeem, which burns the customer's points and records the discount. Tests cover minting to the wrong address, redeeming more points than a customer holds, and redeeming twice.
The team builds the package, runs the tests, and publishes to testnet. They mint 10,000 test points across 500 test addresses, redeem 4,000 of them, and check that the remaining balances add up: 10,000 minted minus 4,000 redeemed leaves 6,000 points outstanding. Only when the testnet numbers match do they plan a mainnet deployment.
What are the common mistakes?
The most common mistakes when creating a Sui smart contract are skipping tests, giving structs the wrong abilities, and publishing to mainnet before the contract has run on testnet.
- Giving a struct copy or drop. A token with the copy ability can be duplicated, and one with drop can be discarded. Choose abilities deliberately for every struct.
- No tests for failure cases. Testing only the happy path leaves the error paths unchecked, and error paths are where funds get stuck.
- Publishing with the wrong address as admin. If the mint or upgrade authority belongs to a throwaway address, you may lose control of the contract.
- Skipping the gas check. Publishing without enough testnet SUI fails partway through and wastes a debugging round.
- Copying a tutorial without understanding it. Tutorial code is a starting point, not a finished contract; read every line before you publish it.
Fix these before mainnet, not after. A contract that is simple, tested, and published to testnet first is a far better starting point than a large contract rushed to mainnet.
Key takeaways
- A Sui smart contract is a Move package of modules, published under a package ID
- Everything on Sui is an object with an owner, which shapes how contracts store state
- Move's resource rules stop coins and tokens being copied or dropped by accident
- Build with sui move build, test with sui move test, and publish with sui client publish
- Test on testnet first and get a security review before anything holding real value goes to mainnet
Frequently asked questions
Do I need real SUI to create a smart contract on Sui?
No. You can build, test and publish on testnet using free testnet SUI from the faucet. You only need real SUI when you publish to mainnet, and you should only do that after testing and a security review.
What language are Sui smart contracts written in?
Sui smart contracts are written in Move, a resource-oriented language. Values such as coins are treated as resources that cannot be copied or dropped by accident, which catches asset-handling bugs at compile time.
How is a Sui contract different from an Ethereum contract?
Sui stores state as objects with owners rather than as storage slots inside a contract, and its contracts are written in Move rather than Solidity. The object model also lets Sui process unrelated transactions in parallel.
Can I update a smart contract after publishing it on Sui?
Packages can be made upgradeable when they are published, with an upgrade authority that controls changes. If you publish a package as immutable, it cannot be changed, so decide the upgrade policy before you publish.
How much does it cost to publish a contract on Sui?
Publishing costs gas paid in SUI, and the amount depends on the size of the package and the network load at the time. On testnet the gas comes from the free faucet, so you can measure the cost there before mainnet.
What should I test before publishing a Sui contract?
Test the happy path and every failure case: bad inputs, transfers that should fail, and calls from the wrong address. Also check that object balances add up after a sequence of operations, not just after one call.