Aptos开发实战:从环境搭建到第一个HelloWorld引言Aptos区块链以其高性能和独特的设计为开发者提供了强大的工具。本篇学习笔记将带你一步步完成Aptos开发环境的搭建,并通过编写第一个HelloWorld项目,帮助你快速掌握Aptos开发的基础流程。从安装Ap
Aptos 区块链以其高性能和独特的设计为开发者提供了强大的工具。本篇学习笔记将带你一步步完成 Aptos 开发环境的搭建,并通过编写第一个 Hello World 项目,帮助你快速掌握 Aptos 开发的基础流程。从安装 Aptos CLI 到项目初始化与测试,本文为你提供了详细的实操指南,让你快速上手 Aptos 开发。
Aptos is a Layer-1 community-driven network, governed by the people who build on it from around the world. It’s decentralized. It’s fast. It’s blockchain at its best.
Aptos 区块链上的每个账户都由一个 32 字节的账户地址标识。 与其他区块链中账户和地址隐式不同,Aptos 上的账户是显式的,需要先创建才能执行交易。 可以通过将 Aptos 代币 (APT) 转移到 Aptos 来显式或隐式创建账户。
Aptos 上有三种类型的账户:
标准账户——这是一个典型的账户,对应一个地址和一对相应的公钥/私钥。 资源账户- 一个没有对应私钥的自主账户,供开发者存储资源或上链发布模块。 对象- 存储在代表单个实体的单个地址内的一组复杂资源。
帐户地址为 32 字节。它们通常显示为 64 个十六进制字符,每个十六进制字符为一个半字节。有时地址以 0x 为前缀。 Aptos区块链默认采用Ed25519签名交易。
Aptos 区块链存储三种类型的数据:
交易:交易表示区块链上的账户正在执行的预期操作(例如转移资产)。 状态:(区块链账本)状态代表交易执行输出的累积,即存储在所有资源内的价值。 事件:交易执行时发布的辅助数据。 只有交易才能改变账本状态。
Install the Aptos CLI on Mac
brew update
brew install aptos
查看版本检查安装是否成功
aptos help
intensive-colearning-aptos on main via 🅒 base took 4.3s
➜ aptos --version
aptos 4.1.0
更新 Aptos
brew update
brew upgrade aptos
更多请参考:
~/Code/Aptos via 🅒 base
➜
mcd hello_aptos
Code/Aptos/hello_aptos via 🅒 base
➜
aptos init
Configuring for profile default
Choose network from [devnet, testnet, mainnet, local, custom | defaults to devnet]
devnet
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 0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35 doesn't exist, creating it and funding it with 100000000 Octas
Account 0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35 funded successfully
---
Aptos CLI is now set up for account 0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35 as profile default!
See the account here: https://explorer.aptoslabs.com/account/0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35?network=devnet
Run `aptos --help` for more information about commands
{
"Result": "Success"
}
Code/Aptos/hello_aptos via 🅒 base took 1m 32.7s
➜
aptos account list
{
"Result": [
{
"0x1::account::Account": {
"authentication_key": "0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35",
"coin_register_events": {
"counter": "0",
"guid": {
"id": {
"addr": "0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35",
"creation_num": "0"
}
}
},
"guid_creation_num": "2",
"key_rotation_events": {
"counter": "0",
"guid": {
"id": {
"addr": "0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35",
"creation_num": "1"
}
}
},
"rotation_capability_offer": {
"for": {
"vec": []
}
},
"sequence_number": "0",
"signer_capability_offer": {
"for": {
"vec": []
}
}
}
}
]
}
Code/Aptos/hello_aptos via 🅒 base took 2.5s
➜
aptos account fund-with-faucet --account 0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35
{
"Result": "Added 100000000 Octas to account 0xee6c038b66df7ed8aa91eb700938003ce29647f402c090ededd89b87a3c70e35"
}
Code/Aptos/hello_aptos via 🅒 base
➜
mcd lesson1
Aptos/hello_aptos/lesson1 via 🅒 base
➜
aptos move init --name lesson1
{
"Result": "Success"
}
Aptos/hello_aptos/lesson1 via 🅒 base took 2.1s
➜
ls
Move.toml scripts sources tests
aptos init
Aptos/hello_aptos/lesson1 via 🅒 base
➜ tree . -L 6 -I 'build'
.
├── Move.toml
├── scripts
├── sources
│ └── main.move
└── tests
4 directories, 2 files
Move.toml
代码[package]
name = "lesson1"
version = "1.0.0"
authors = []
[addresses]
Lesson1 = "dfc044d199141627a77203495452bc5165c070edbcbf357f211096fbe974ddf7"
[dev-addresses]
[dependencies.AptosFramework]
git = "https://github.com/aptos-labs/aptos-core.git"
rev = "mainnet"
subdir = "aptos-move/framework/aptos-framework"
[dev-dependencies]
main.move
代码module Lesson1::HelloWorld {
#[test_only]
use std::debug::print;
#[test_only]
use std::string::utf8;
#[test]
fun test_hello_world() {
print(&utf8(b"hello world"));
}
}
Aptos/hello_aptos/lesson1 via 🅒 base took 25.0s
➜ aptos move test
INCLUDING DEPENDENCY AptosFramework
INCLUDING DEPENDENCY AptosStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING lesson1
Running Move unit tests
[debug] "hello world"
[ PASS ] 0xdfc044d199141627a77203495452bc5165c070edbcbf357f211096fbe974ddf7::HelloWorld::test_hello_world
Test result: OK. Total tests: 1; passed: 1; failed: 0
{
"Result": "Success"
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!