diff --git a/mover/Nii11L/code/task3/hello_nft/Move.lock b/mover/Nii11L/code/task3/hello_nft/Move.lock new file mode 100644 index 000000000..54fe06f53 --- /dev/null +++ b/mover/Nii11L/code/task3/hello_nft/Move.lock @@ -0,0 +1,40 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 3 +manifest_digest = "EE1F76C6FE60CAFA64EAAF0DC41FBB9535F13F6BD9A6BA7AA6B695AE423513B4" +deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082" +dependencies = [ + { id = "Sui", name = "Sui" }, +] + +[[move.package]] +id = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +id = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { id = "MoveStdlib", name = "MoveStdlib" }, +] + +[move.toolchain-version] +compiler-version = "1.37.1" +edition = "2024.beta" +flavor = "sui" + +[env] + +[env.suiscan-testnet-rpc] +chain-id = "4c78adac" +original-published-id = "0xbb3e0dc4f7eb83409e917506725d9bf1c579678fa4393a40c85a98279328a4c4" +latest-published-id = "0xbb3e0dc4f7eb83409e917506725d9bf1c579678fa4393a40c85a98279328a4c4" +published-version = "1" + +[env.suiscan-mainnet-rpc] +chain-id = "35834a8a" +original-published-id = "0x1db724adfe00d5e36262f31a4ba4f1227ee11d2e8ecbfe9a5b20497f32d4c4af" +latest-published-id = "0x1db724adfe00d5e36262f31a4ba4f1227ee11d2e8ecbfe9a5b20497f32d4c4af" +published-version = "1" diff --git a/mover/Nii11L/code/task3/hello_nft/Move.toml b/mover/Nii11L/code/task3/hello_nft/Move.toml new file mode 100644 index 000000000..bac03b2a2 --- /dev/null +++ b/mover/Nii11L/code/task3/hello_nft/Move.toml @@ -0,0 +1,37 @@ +[package] +name = "hello_nft" +edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move +# license = "" # e.g., "MIT", "GPL", "Apache 2.0" +# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"] + +[dependencies] +Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" } + +# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`. +# Revision can be a branch, a tag, and a commit hash. +# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" } + +# For local dependencies use `local = path`. Path is relative to the package root +# Local = { local = "../path/to" } + +# To resolve a version conflict and force a specific version for dependency +# override use `override = true` +# Override = { local = "../conflicting/version", override = true } + +[addresses] +hello_nft = "0x0" + +# Named addresses will be accessible in Move as `@name`. They're also exported: +# for example, `std = "0x1"` is exported by the Standard Library. +# alice = "0xA11CE" + +[dev-dependencies] +# The dev-dependencies section allows overriding dependencies for `--test` and +# `--dev` modes. You can introduce test-only dependencies here. +# Local = { local = "../path/to/dev-build" } + +[dev-addresses] +# The dev-addresses section allows overwriting named addresses for the `--test` +# and `--dev` modes. +# alice = "0xB0B" + diff --git a/mover/Nii11L/code/task3/hello_nft/sources/hello_nft.move b/mover/Nii11L/code/task3/hello_nft/sources/hello_nft.move new file mode 100644 index 000000000..9db539eea --- /dev/null +++ b/mover/Nii11L/code/task3/hello_nft/sources/hello_nft.move @@ -0,0 +1,62 @@ +module hello_nft::my_nft{ + use std::ascii::String; + use sui::url::{Self, Url}; + + public struct MyNFT has key, store { + id: UID, + name: String, + description: String, + image_url: Url, + } + + #[allow(lint(self_transfer))] + public entry fun mint_to_sender( + name: String, + description: String, + image_url: String, + ctx: &mut TxContext, + ) { + let nft = MyNFT { + id: object::new(ctx), + name: name, + description: description, + image_url: url::new_unsafe(image_url), + }; + + transfer::transfer(nft, ctx.sender()); + } + + public entry fun mint_to_address( + minter: address, + name: String, + description: String, + image_url: String, + ctx: &mut TxContext, + ) { + let nft = MyNFT { + id: object::new(ctx), + name: name, + description: description, + image_url: url::new_unsafe(image_url), + }; + + transfer::transfer(nft, minter); + } + + public fun name(nft: &MyNFT) : String { + nft.name + } + + public fun description(nft: &MyNFT) : String { + nft.description + } + + public fun image_url(nft: &MyNFT) : String { + nft.image_url.inner_url() + } + + public entry fun burn(nft: MyNFT, _: &mut TxContext) { + let MyNFT { id, .. } = nft; + id.delete(); + } +} diff --git a/mover/Nii11L/code/task3/hello_nft/tests/hello_nft_tests.move b/mover/Nii11L/code/task3/hello_nft/tests/hello_nft_tests.move new file mode 100644 index 000000000..32b844d06 --- /dev/null +++ b/mover/Nii11L/code/task3/hello_nft/tests/hello_nft_tests.move @@ -0,0 +1,64 @@ +#[test_only] +module hello_nft::hello_nft_tests{ + use sui::test_scenario::{Self}; + use hello_nft::my_nft::{Self, MyNFT}; + use std::ascii; + + #[test] + fun test_mint_to_sender() { + let owner = @0xA; + let mut scenario = test_scenario::begin(owner); + + scenario.next_tx(owner); + { + my_nft::mint_to_sender( + ascii::string(b"My NFT"), + ascii::string(b"This is my NFT"), + ascii::string(b"https://example.com/image.png"), + scenario.ctx(), + ); + }; + + scenario.next_tx(owner); + { + assert!(test_scenario::has_most_recent_for_sender(&scenario), 1); + let nft = scenario.take_from_sender(); + assert!(my_nft::name(&nft) == ascii::string(b"My NFT"), 1); + assert!(my_nft::description(&nft) == ascii::string(b"This is my NFT"), 1); + assert!(my_nft::image_url(&nft) == ascii::string(b"https://example.com/image.png"), 1); + test_scenario::return_to_sender(&scenario, nft) + }; + + scenario.end(); + } + + #[test] + fun test_mint_to_address() { + let owner = @0xA; + let minter = @0xB; + let mut scenario = test_scenario::begin(owner); + + scenario.next_tx(owner); + { + my_nft::mint_to_address( + minter, + ascii::string(b"My NFT"), + ascii::string(b"This is my NFT"), + ascii::string(b"https://example.com/image.png"), + scenario.ctx(), + ); + }; + + scenario.next_tx(owner); + { + assert!(test_scenario::has_most_recent_for_address( minter), 1); + let nft = scenario.take_from_address(minter); + assert!(my_nft::name(&nft) == ascii::string(b"My NFT"), 1); + assert!(my_nft::description(&nft) == ascii::string(b"This is my NFT"), 1); + assert!(my_nft::image_url(&nft) == ascii::string(b"https://example.com/image.png"), 1); + test_scenario::return_to_address(minter, nft); + }; + + scenario.end(); + } +} \ No newline at end of file diff --git a/mover/Nii11L/images/task3-nft.png b/mover/Nii11L/images/task3-nft.png new file mode 100644 index 000000000..43a70e9dc Binary files /dev/null and b/mover/Nii11L/images/task3-nft.png differ diff --git a/mover/Nii11L/readme.md b/mover/Nii11L/readme.md index abb663774..5354a49c0 100644 --- a/mover/Nii11L/readme.md +++ b/mover/Nii11L/readme.md @@ -26,10 +26,10 @@ - [x] `Faucet Coin` address2 mint hash: 5AkEKoaBpJ289xoX3FVaUTPdATLu2T8HEt86bXp1w4Ep ## 03 move NFT -- [] nft package id : -- [] nft object id : -- [] 转账 nft hash: -- [] scan上的NFT截图:![Scan截图](./images/你的图片地址) +- [x] nft package id : 0x1db724adfe00d5e36262f31a4ba4f1227ee11d2e8ecbfe9a5b20497f32d4c4af +- [x] nft object id : 0x6793be4728f8a42ffafc1c91756a207abfd5bd6f6d788a5419e9bed6218f03c7 +- [x] 转账 nft hash: BB8LJ4qQMh5Kp1zWVWTd3wgSUbQ2qw8GJBfs1JiJpSVu +- [x] scan上的NFT截图:![Scan截图](./images/task3-nft.png) ## 04 Move Game - [] game package id :