L0

Quick Start

5分钟体验 Æternity 区块链开发

Mentors - 技术指导

首先添加以下技术顾问为您提供入门技术支持:

孙百鑫
BoxWallet等创始人
微信二维码
sunbaixin
刘勃
AEKnow等创始人
刘勃微信
liubo_ae
添加微信时请备注"Æternity 开发者"
Step 1 下载 PyStart 并创建账户
下载 PyStart

PyStart 是专为 Æternity 开发打造的 Python 开发环境,集成了所有必要的 SDK 和工具。

下载 PyStart

PyStart 包含:Python 3.12、aepp-sdk-python、Sophia 编译器、示例项目


创建 Æternity 账户

下载解压后,在 PyStart 环境中运行以下代码创建账户:

# create_account.py
from aeternity.signing import Account
from mnemonic import Mnemonic
import json
import getpass

# 1. 生成助记词 (12个单词)
mnemo = Mnemonic('english')
mnemonic_words = mnemo.generate(strength=128)
print('='*60)
print('📝 助记词 (请拄写到纸上保存):')
print('='*60)
print(mnemonic_words)
print('='*60)

# 2. 从助记词生成账户
seed = mnemo.to_seed(mnemonic_words)
account = Account.from_secret_key(seed[:32].hex())
address = account.get_address()

print(f'\n地址: {address}')

# 3. 生成 Keystore 文件 (密码加密)
password = getpass.getpass('请设置 Keystore 密码: ')
keystore = account.export_keystore(password)

# 保存到 dev.json
with open('dev.json', 'w') as f:
    json.dump(keystore, f, indent=2)

print('\n✅ Keystore 已保存: dev.json')
print('后续使用时,可通过 dev.json + 密码 恢复账户')

运行后输出示例:

============================================================
📝 助记词 (请拄写到纸上保存):
============================================================
word1 word2 word3 word4 word5 word6 word7 word8 word9 word10 word11 word12
============================================================

地址: ak_2QkttUgEyPixKzqXkJ4LX7ugbRjwCDWPBT4p4M2r8brjxUxUYd
请设置 Keystore 密码: ********

✅ Keystore 已保存: dev.json
助记词:拄写到纸上,离线保存
Keystore:密码加密,方便日常使用
如何从 Keystore 恢复账户?
# 从 dev.json 恢复账户
from aeternity.signing import Account
import json

with open('dev.json', 'r') as f:
    keystore = json.load(f)

account = Account.from_keystore(keystore, 'your_password')
print(f'账户恢复成功: {account.get_address()}')
Step 2 获取测试网 AE

有两种方式获取测试网 AE:

方式一:联系 Mentor

联系上方任一 Mentor,说明你的开发需求,即可获得测试 AE。

查看 Mentors
方式二:测试网 Faucet

直接访问测试网 Faucet 领取免费测试币。

Testnet Faucet
Step 3 发送首笔交易

使用 dev.json 发送 1 AE 到指定地址:

# send_tx.py
from aeternity.node import NodeClient
from aeternity.signing import Account
import json
import getpass

# 1. 连接测试网
node = NodeClient('https://testnet.aeternity.io')

# 2. 加载账户
with open('dev.json', 'r') as f:
    keystore = json.load(f)
account = Account.from_keystore(keystore, getpass.getpass('Keystore 密码: '))

print(f'账户: {account.get_address()}')
print(f'余额: {node.get_balance(account.get_address()) / 1e18} AE')

# 3. 发送 1 AE
recipient = 'ak_fCCw1JEkvXdztZxk8FRGNAkvmArhVeow89e64yX4AxbCPrVh5'
amount = int(1 * 1e18)  # 1 AE

tx = node.spend(account, recipient, amount)
print(f'\n✅ 交易成功! Hash: {tx["hash"]}')
print(f'查看: https://testnet.aescan.io/transactions/{tx["hash"]}')
成功后可在 testnet.aescan.io 查看交易详情
Step 4 更进一步:链上存证 - 数据上链
Payload 用途:发送带 Payload 的交易,将消息永久存储在区块链上:存证、留言、带备注转账、应用数据记录等
永久存储:不可篡改、不可删除
公开透明:任何人可查阅

# chain_message.py - 链上存证
from aeternity.node import NodeClient
from aeternity.signing import Account
import json
import getpass

# 加载账户
node = NodeClient('https://testnet.aeternity.io')
with open('dev.json', 'r') as f:
    keystore = json.load(f)
account = Account.from_keystore(keystore, getpass.getpass('Keystore 密码: '))

# 编写链上留言
message = "Hello Æternity! 我的第一笔链上消息 🚀"
payload = message.encode('utf-8')

# 发送带 Payload 的交易
recipient = 'ak_fCCw1JEkvXdztZxk8FRGNAkvmArhVeow89e64yX4AxbCPrVh5'
tx = node.spend(account, recipient, int(0.01 * 1e18), payload=payload)

print(f'✅ 链上存证成功!')
print(f'消息: {message}')
print(f'Hash: {tx["hash"]}')
print(f'查看: https://testnet.aescan.io/transactions/{tx["hash"]}')
Congratulations!
恭喜你完成了 Quick Start!

在过去的几分钟里,你已经掌握了:

区块链基础
  • 创建助记词账户与 Keystore
  • 发送链上交易(转账)
  • 理解 Payload 与数据存证
  • 使用区块链浏览器查询
Python 开发入门
  • 编写并运行 Python 脚本
  • 使用 SDK 调用节点 API
  • JSON 文件读写操作
  • 安全的密码输入处理
你已经走出了第一步! 无论是 Web3 还是 Python,继续练习就会越来越熟练。推荐试试修改代码,改变金额、改变消息,多发几笔交易给自己。

准备好了吗?选择一个方向继续深入 ↓