Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions my_nft/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/*
56 changes: 56 additions & 0 deletions my_nft/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "198F8D2C6C9494D80E47F5DA94532E105BCDFC1DFC3B4C6E03849FBF9803D9BE"
deps_digest = "F9B494B64F0615AED0E98FC12A85B85ECD2BC5185C22D30E7F67786BB52E507C"
dependencies = [
{ id = "Bridge", name = "Bridge" },
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
{ id = "SuiSystem", name = "SuiSystem" },
]

[[move.package]]
id = "Bridge"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", subdir = "crates/sui-framework/packages/bridge" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
{ id = "SuiSystem", name = "SuiSystem" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
id = "SuiSystem"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "664b05b3b047c5bb03979d093660176176ea6175", subdir = "crates/sui-framework/packages/sui-system" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
{ id = "Sui", name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.56.2"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0xa068cbfeb2abe460f67616d601f6e6ec0c7b4741c4327dae61124ba43c328f56"
latest-published-id = "0xa068cbfeb2abe460f67616d601f6e6ec0c7b4741c4327dae61124ba43c328f56"
published-version = "1"
36 changes: 36 additions & 0 deletions my_nft/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
name = "my_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]

# 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]
my_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"

64 changes: 64 additions & 0 deletions my_nft/sources/display_nft.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module my_nft::display_nft {
use std::string;
use std::string::{utf8, String};
use sui::tx_context::{sender};
use sui::package;
use sui::display;

// 定义 NFT 的结构体
public struct MyNFT has key, store {
id: UID, // 唯一标识符,确保每个 NFT 是独一无二的
name: String, // NFT 的名称
image_url: String, // NFT 的图片链接
}

// 定义用于初始化的结构体
public struct DISPLAY_NFT has drop {}

// 初始化函数,设置 NFT 的显示字段
fun init(otw: DISPLAY_NFT, ctx: &mut TxContext) {
let keys = vector[
utf8(b"name"), // 显示字段:名称
utf8(b"link"), // 显示字段:链接
utf8(b"image_url"), // 显示字段:图片链接
utf8(b"description"), // 显示字段:描述
utf8(b"project_url"), // 显示字段:项目链接
utf8(b"creator"), // 显示字段:创建者
];

let values = vector[
utf8(b"{name}"), // 名称的占位符
utf8(b"https://sui-heroes.io/hero/{id}"), // 动态链接
utf8(b"{image_url}"), // 图片链接占位符
utf8(b"A true Hero of the Sui ecosystem!"), // 固定描述
utf8(b"https://sui-heroes.io"), // 固定项目链接
utf8(b"Unknown Sui Fan"), // 默认创建者
];

let publisher = package::claim(otw, ctx); // 声明发布者权限

let mut display = display::new_with_fields<MyNFT>(
&publisher, keys, values, ctx
); // 创建显示对象,并设置字段

display::update_version(&mut display); // 更新显示版本

transfer::public_transfer(publisher, sender(ctx)); // 将发布者对象转移给调用者
transfer::public_transfer(display, sender(ctx)); // 将显示对象转移给调用者

let nft = MyNFT {
id: object::new(ctx), // 创建新的唯一 ID
name: string::utf8(b"inward world nft"), // 默认名称
image_url: string::utf8(b"https://avatars.githubusercontent.com/u/72508072?v=4&size=64"), // 默认自己的github头像
};

transfer::public_transfer(nft, sender(ctx)); // 将创建的 NFT 转移给调用者
}

// 铸造 NFT 的函数
public entry fun mint(name: String, image_url: String, ctx: &mut TxContext) {
let id = object::new(ctx); // 创建新的唯一 ID
let nft = MyNFT { id, name, image_url }; // 构造 NFT
transfer::public_transfer(nft, sender(ctx)); // 将 NFT 转移给调用者
}
}
9 changes: 9 additions & 0 deletions my_nft/sources/my_nft.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
/// Module: my_nft
module my_nft::my_nft;
*/

// For Move coding conventions, see
// https://docs.sui.io/concepts/sui-move-concepts/conventions


18 changes: 18 additions & 0 deletions my_nft/tests/my_nft_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module my_nft::my_nft_tests;
// uncomment this line to import the module
// use my_nft::my_nft;

const ENotImplemented: u64 = 0;

#[test]
fun test_my_nft() {
// pass
}

#[test, expected_failure(abort_code = ::my_nft::my_nft_tests::ENotImplemented)]
fun test_my_nft_fail() {
abort ENotImplemented
}
*/