Skip to content

Move Contract Compilation Errors - TreasuryCap, Mint, Burn, and Struct Visibility Issues #21342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BHKFile opened this issue Feb 24, 2025 · 14 comments
Assignees
Labels
cli Command line tools

Comments

@BHKFile
Copy link

BHKFile commented Feb 24, 2025

I am facing multiple compilation errors while trying to build and deploy a Move smart contract on Sui. The contract is designed to create a token (LQX) with functionalities such as minting, burning, and rebalancing based on a price feed. However, multiple issues are preventing successful compilation.

Steps to Reproduce

  1. Clone the repository:
    git clone https://github.com/MystenLabs/sui.git
  2. Navigate to the contract directory:
    cd ~/lqx_token
  3. Run the build command:
    sui move build
  4. Observe errors.

Errors Encountered

🔹 1. TreasuryCap Function Missing

Error:

error[E03003]: unbound module member
   ┌─ ./sources/lqx.move:3:40
   │
3 │     use sui::coin::{Coin, TreasuryCap, create_treasury_cap, mint, burn, value};
  │                                        ^^^^^^^^^^^^^^^^^^^ Invalid 'use'. Unbound member 'create_treasury_cap' in module 'sui::coin'

Expected Fix:

  • The function create_treasury_cap() is not available in sui::coin, yet it is needed for TreasuryCap<LQX>.
  • Is there a new method to initialize a TreasuryCap?
  • If the function was removed or replaced, what is the correct approach?

🔹 2. Struct Declarations Require Visibility Modifiers

Error:

error[E01003]: invalid modifier
  ┌─ ./sources/lqx.move:8:5
  │
8 │     struct LQX has key, store {
  │     ^^^^^^ Invalid struct declaration. Internal struct declarations are not yet supported
  │
  = Visibility annotations are required on struct declarations from the Move 2024 edition onwards.

Expected Fix:

  • Should struct declarations now be explicitly marked public?
    Example:
    public struct LQX has key, store {
  • Or should structs be placed within a different visibility scope?

🔹 3. Mint Function Issues (mint<LQX> Wrong Arguments)

Error:

error[E04005]: expected a single type
   ┌─ ./sources/lqx.move:45:13
   │
39 │     public entry fun mint(
   │                      ---- Expected a single type, but found expression list type: '()'
   ·
45 │         let coin = mint<LQX>(&mut treasury.cap, amount, ctx);
   │             ^^^^ Invalid type for local

Expected Fix:

  • Should mint<LQX> use a different number of arguments?
  • The error suggests that mint<LQX>() expects different parameters than currently used.

🔹 4. Burn Function Requires Different Arguments

Error:

error[E04007]: incompatible types
   ┌─ ./sources/lqx.move:55:9
   │
18 │         cap: TreasuryCap<LQX>,
   │              ---------------- Given: 'sui::coin::TreasuryCap<0x186303B5394B015DFF7733DA3E5F1059BB77AAFA36122173B6310EC22CD8D262::lqx::LQX>'
   ·
51 │         treasury: &mut Treasury,
   │                        -------- Expected: '0x186303B5394B015DFF7733DA3E5F1059BB77AAFA36122173B6310EC22CD8D262::lqx::Treasury'
   ·
55 │         burn(&mut treasury.cap, coin);
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Invalid call of 'sui::coin::burn'. Invalid argument for parameter 'treasury'

Expected Fix:

  • How should the burn function be structured?
  • What correct parameters does sui::coin::burn() require?

🔹 5. Structs with drop Ability Must Have Drop-Able Fields

Error:

error[E05001]: ability constraint not satisfied
   ┌─ ./sources/lqx.move:21:13
   │
21 │         id: UID,
   │             ^^^
   │             │
   │             Invalid field type. The struct was declared with the ability 'drop' so all fields require the ability 'drop'
   │             The type 'sui::object::UID' does not have the ability 'drop'

Expected Fix:

  • Should UID include the drop ability?
  • If not, how should we structure the id field inside objects with drop?

🔹 6. Transfer Function (ctx.sender() Not Supported in Legacy Move)

Error:

error[E13001]: feature is not supported in specified edition
   ┌─ ./sources/lqx.move:95:9
   │
95 │         transfer::public_transfer(coin, ctx.sender());
   │                                         ^^^^^^^^^^^^ Method syntax is not supported by current edition 'legacy'; the '2024' edition supports this feature
   │
   = You can update the edition in the 'Move.toml', or via command line flag if invoking the compiler directly.

Expected Fix:

  • Should we update to Move 2024?
  • If legacy Move must be used, is there an alternative to ctx.sender()?

System Information

  • Sui Version:** 1.17.0
  • Move Edition:** Legacy
  • OS: Ubuntu 22.04 LTS
  • Terminal: WSL (Windows Subsystem for Linux)

  1. 🔹 What is the correct way to initialize TreasuryCap<LQX> in Move 2024?
  2. 🔹 What should replace ctx.sender() if Move 2024 is unavailable?
  3. 🔹 Are mint() and burn() expected to have different parameter structures?
  4. 🔹 Do all structs now require public struct visibility?
Copy link
Contributor

Thank you for opening this issue, a team member will review it shortly. Until then, please do not interact with any users that claim to be from Sui support and do not click on any links!

@stefan-mysten
Copy link
Contributor

Your Sui CLI version is very old.

We do not have access to your source code cd ~/lqx_token, so we cannot reproduce. Please publish your Move.toml file and update your CLI, and then try again.

@stefan-mysten stefan-mysten reopened this Feb 24, 2025
@stefan-mysten stefan-mysten self-assigned this Feb 24, 2025
@stefan-mysten stefan-mysten added the cli Command line tools label Feb 24, 2025
@BHKFile
Copy link
Author

BHKFile commented Feb 24, 2025

[package]
name = "lquix_token"
version = "0.0.1"
edition = "2024" # ✅ Fixed: Enables Move 2024 features
published-at = "0x0"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "t>

[addresses]
lquix_token = "0x0"
sui = "0x2" # ✅ Fixed: Sui framework uses 0x2 instead of 0x0

@BHKFile
Copy link
Author

BHKFile commented Feb 24, 2025

Your Sui CLI version is very old.

We do not have access to your source code cd ~/lqx_token, so we cannot reproduce. Please publish your Move.toml file and update your CLI, and then try again.

Done

@stefan-mysten
Copy link
Contributor

Does it work after updating your CLI?

@BHKFile
Copy link
Author

BHKFile commented Feb 24, 2025

Does it work after updating your CLI?

lqx@DESKTOP-D6DNN8E:~/lqx_token$ sui --version
sui 1.42.3-21c8e55773ac

Yes, it did work.

@stefan-mysten
Copy link
Contributor

Change these to your Move.toml

[package]
name = "lquix_token"
version = "0.0.1"
edition = "2024"
published-at = "0x0"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet">

[addresses]
lquix_token = "0x0"

@stefan-mysten
Copy link
Contributor

These are imported by default

// Part 1: These imports are provided by default
// use sui::object::{Self, UID};
// use sui::transfer;
// use sui::tx_context::{Self, TxContext};

@stefan-mysten
Copy link
Contributor

For the rest, I think you have issues in your Move code. Check the coin module here: https://docs.sui.io/references/framework/sui/coin

@stefan-mysten
Copy link
Contributor

For #1: you need a different function:

public fun create_currency<T: drop>(

For #2, yes, you need to make it public.

@stefan-mysten
Copy link
Contributor

For the rest, I would recommend to go through the move-book: https://move-book.com/

@BHKFile
Copy link
Author

BHKFile commented Feb 25, 2025

For the rest, I would recommend to go through the move-book: https://move-book.com/

I still receive the following error:


lqx@DESKTOP-D6DNN8E:~/lqx_token$ sui move build --force
Failed to build Move modules: Failed to resolve dependencies for package 'lqx_token'

Caused by:
    0: Parsing manifest for 'Sui'
    1: No such file or directory (os error 2).

@stefan-mysten
Copy link
Contributor

stefan-mysten commented Feb 25, 2025

Delete the .move folder in your ~/ path. It might be a caching issue, when you usually get this error or it's because the git clone did not work properly.

Also delete the build folder in your lqx_token folder.

@BHKFile
Copy link
Author

BHKFile commented Feb 26, 2025

Delete the .move folder in your ~/ path. It might be a caching issue, when you usually get this error or it's because the git clone did not work properly.

Also delete the build folder in your lqx_token folder.

Done, it didn't help. I also tried to deploy the smart contract in movestudio.dev, but it seems there is a server issue.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Command line tools
Projects
None yet
Development

No branches or pull requests

2 participants