AptosMoveNFT项目实操指南:从开发到部署全流程解析随着区块链技术的不断发展,非同质化代币(NFT)已经成为数字资产管理的关键组成部分,为资产所有权和交易方式带来了革命性的变化。Aptos提供了一种创新的数字资产(DA)标准,使开发者能够轻松创建和管理链上独特的资产。通过集合
随着区块链技术的不断发展,非同质化代币(NFT)已经成为数字资产管理的关键组成部分,为资产所有权和交易方式带来了革命性的变化。Aptos 提供了一种创新的数字资产 (DA) 标准,使开发者能够轻松创建和管理链上独特的资产。通过 集合 (Collection) 和 代币 (Token) 的组合,开发者不仅可以轻松创建 NFT,还能为这些资产附加丰富的元数据(如图像、视频链接等),以增强用户的互动性和体验。
本文深入介绍了 Aptos 数字资产 (DA) 标准的核心功能,重点展示了如何通过 集合 (Collection) 和 代币 (Token) 来创建和管理 NFT。我们将从项目初始化开始,详细讲解项目结构设计、智能合约编写、编译与部署过程,以及如何在 Aptos 区块链上调用和操作 NFT 项目。通过本教程的分步实践,读者将全面掌握 Aptos 上的 NFT 开发流程,学习如何通过智能合约实现链上资产管理与交易。
Aptos 数字资产 (DA) 标准
Aptos 的数字资产 (DA) 标准是其独特的非同质化代币 (NFT) 标准。NFT 代表链上唯一的数字资产,并通过集合的形式进行存储。
该标准由两个对象实现:
hello_aptos/AptosNFTFactory on main [?] via 🅒 base
➜ aptos init
Configuring for profile default
Choose network from [devnet, testnet, mainnet, local, custom | defaults to devnet]
testnet
Enter your private key as a hex literal (0x...) [Current: None | No input: Generate new key (or keep one if present)]
No key given, generating key...
Account 0xe6eba0c086998fbd5ad141e4b30942e38bc77e2d5696bf6b1786f7a7722415c8 doesn't exist, creating it and funding it with 100000000 Octas
Account 0xe6eba0c086998fbd5ad141e4b30942e38bc77e2d5696bf6b1786f7a7722415c8 funded successfully
---
Aptos CLI is now set up for account 0xe6eba0c086998fbd5ad141e4b30942e38bc77e2d5696bf6b1786f7a7722415c8 as profile default!
See the account here: https://explorer.aptoslabs.com/account/0xe6eba0c086998fbd5ad141e4b30942e38bc77e2d5696bf6b1786f7a7722415c8?network=testnet
Run `aptos --help` for more information about commands
{
"Result": "Success"
}
tree . -L 6 -I 'build'
.
├── Move.toml
├── scripts
├── sources
│ └── nft.move
└── tests
4 directories, 2 files
Move.toml
文件[package]
name = "AptosNFTFactory"
version = "1.0.0"
authors = []
[addresses]
contract = "_"
[dev-addresses]
[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"
# https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-token-objects/Move.toml
[dependencies.AptosTokenObjects]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-token-objects"
[dev-dependencies]
nft.move
文件module contract::nft {
use aptos_token_objects::collection;
use std::option::Self;
use std::string;
use aptos_token_objects::token;
public entry fun create_collection(creator: &signer) {
let max_supply = 1000;
let royalty = option::none();
// Maximum supply cannot be changed after collection creation
collection::create_fixed_collection(
creator,
string::utf8(b"My Collection Description"),
max_supply,
string::utf8(b"Qiao Collection"),
royalty,
string::utf8(b"ipfs://Qma8NPQhCWjZZdi42e9ZmYjSPb76sgknCrztnCBXJHJczq/2.png")
);
}
public entry fun mint_token(creator: &signer) {
let royalty = option::none();
token::create(
creator,
string::utf8(b"Qiao Collection"),
string::utf8(b"My NFT Description"),
string::utf8(b"QiaoToken"),
royalty,
string::utf8(b"ipfs://Qma8NPQhCWjZZdi42e9ZmYjSPb76sgknCrztnCBXJHJczq/3.png")
);
}
}
hello_aptos/AptosNFTFactory on main [?] via 🅒 base took 1m 2.3s
➜ aptos move compile --named-addresses contract=default --skip-fetch-latest-git-deps
Compiling, may take a little while to download git dependencies...
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY AptosTokenObjects
INCLUDING DEPENDENCY MoveStdlib
BUILDING AptosNFTFactory
warning[W09001]: unused alias
┌─ /Users/qiaopengjun/Code/Aptos/hello_aptos/AptosNFTFactory/sources/nft.move:3:29
│
3 │ use std::option::{Self, Option};
│ ^^^^^^ Unused 'use' of alias 'Option'. Consider removing it
warning: unused alias
┌─ /Users/qiaopengjun/Code/Aptos/hello_aptos/AptosNFTFactory/sources/nft.move:3:29
│
3 │ use std::option::{Self, Option};
│ ^^^^^^ Unused 'use' of alias 'Option'. Consider removing it
{
"Result": [
"e6eba0c086998fbd5ad141e4b30942e38bc77e2d5696bf6b1786f7a7722415c8::nft"
]
}
hello_aptos/AptosNFTFactory on main [?] via 🅒 base took 4.3s
➜ aptos move deploy-object --address-name contract
Compiling, may take a little while to download git dependencies...
UPDATING GIT DEPENDENCY https://github.com/aptos-labs/aptos-core.git
UPDATING GIT DEPENDENCY https://github.com/aptos-labs/aptos-core.git
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY AptosTokenObjects
INCLUDING DEPENDENCY MoveStdlib
BUILDING AptosNFTFactory
Do you want to deploy this package at object address 0x05b86a98c7976f97000b08c1df62ddd3948128d64acf50a7fa13d78dfc67181b [yes/no] >
yes
package size 1708 bytes
Do you want to submit a transaction for a range of [212400 - 318600] Octas at a gas unit price of 100 Octas? [yes/no] >
yes
Transaction submitted: https://explorer.aptoslabs.com/txn/0xb6f8785228763792dd36280eaaf619e84e3c81bbc80f1a40f3ddfcfe0ba05333?network=testnet
Code was successfully deployed to object address {}. 0x05b86a98c7976f97000b08c1df62ddd3948128d64acf50a7fa13d78dfc67181b
{
"Result": "Success"
}
create_collection
方法mint_token
方法如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!