Code to paste
/// Module: todo_list
module todo_list::todo_list;
use std::string::String;
use sui::transfer;
/// List of todos. Can be managed by the owner and shared with others.
public struct TodoList has key, store {
id: UID,
items: vector<String>
}
/// Create a new todo list and transfer it to the caller.
public entry fun new(ctx: &mut TxContext) {
let list = TodoList {
id: object::new(ctx),
items: vector[]
};
transfer::transfer(list, ctx.sender());
}
/// Add a new todo item to the list.
public fun add(list: &mut TodoList, item: String) {
list.items.push_back(item);
}
/// Remove a todo item from the list by index.
public entry fun remove(list: &mut TodoList, index: u64): String {
list.items.remove(index)
}
/// Delete the list and the capability to manage it.
public entry fun delete(list: TodoList) {
let TodoList { id, items: _ } = list;
id.delete();
}
/// Get the number of items in the list.
public entry fun length(list: &TodoList): u64 {
list.items.length()
}With your updated new function that creates and transfers the TodoList, you can now call:
sui client call --package 0x99706b6e72e3caa12466519fad43a82bc6a4ea7b833100f803296034ef231b12 --module todo_list --function new
This should work without the "UnusedValueWithoutDrop" error because the new function now handles the transfer automatically. After creating a TodoList, you can:
Add items:
sui client call --package 0x99706b6e72e3caa12466519fad43a82bc6a4ea7b833100f803296034ef231b12 --module todo_list --function add --args <todo_list_object_id> "Buy groceries"Check length:
sui client call --package 0x99706b6e72e3caa12466519fad43a82bc6a4ea7b833100f803296034ef231b12 --module todo_list --function length --args <todo_list_object_id>Try creating a new TodoList now with the updated package ID! Remember to get it after calling the new function