這步驟會帶大家上傳到 Aptos 鏈上
首先我們要初始化一個新的 Aptos 帳戶和部署配置,並存入一定金額到帳戶裡來支付 Gap 費用。
在 userinfo root 層執行,都使用 default 設定就好
$ ~/bin/aptos init
成功後會看到如下
除了成功之外,包含新帳戶私鑰的部署配置會在 .aptos/config.yaml
裡 (root 目錄),切記 永遠不要跟別人分享你的私鑰,如果想要更改配置,可以再次運行 aptos init
Configuring for profile default
Enter your rest endpoint [Current: None | No input: https://fullnode.devnet.aptoslabs.com/v1]
No rest url given, using https://fullnode.devnet.aptoslabs.com/v1...
Enter your faucet endpoint [Current: None | No input: https://faucet.devnet.aptoslabs.com | 'skip' to not use a faucet]
No faucet url given, using https://faucet.devnet.aptoslabs.com...
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 1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c doesn't exist, creating it and funding it with 10000 Octas
Aptos is now set up for account 1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c! Run `aptos help` for more information about commands
{
"Result": "Success"
}
拿到地址後,我們回到 Move.toml 修改 address
我們需要在產生的地址前加上 0x
當作前綴,以這邊的例子,我們最後會變成 0x1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c
[addresses]
sender = "0x1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c"
接著,我們將帳戶存入金額
$ ~/bin/aptos account fund-with-faucet --account default --amount 500000000000000
最後一步,發布我們的 package
可以使用 max-gas
來限制最大支付 gas 費用
$ ~/bin/aptos move publish --max-gas 50000
沒意外我們會看到以下結果,恭喜!
{
"Result": {
"transaction_hash": "0xac0f165d7d1935a06b855a4ddbec918adc7687bdfbe9f8dc496a61ba66fbf798",
"gas_used": 6892,
"gas_unit_price": 100,
"sender": "1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c",
"sequence_number": 0,
"success": true,
"timestamp_us": 1666102501887579,
"version": 8119661,
"vm_status": "Executed successfully"
}
}
部署後,可以向 Aptos 區塊鏈發送交易
function-id 後包含已部署的合約和函數名稱路徑
並且加入參數
以這個例子,合約 id 拿剛剛 sender 的 address,參數可以隨意加上
~/bin/aptos move run --function-id 0x1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c::user_info::set_username --args string:"IronMan30"
沒意外會看到下面結果
{
"Result": {
"transaction_hash": "0xedd1ad54943271da6774d16b2f8a7e4870d4edfa730141c81394c4d8007cc8af",
"gas_used": 699,
"gas_unit_price": 100,
"sender": "1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c",
"sequence_number": 1,
"success": true,
"timestamp_us": 1666107035220552,
"version": 8207421,
"vm_status": "Executed successfully"
}
}
可以透過兩個方式檢查是否成功
Aptos Explorer: https://explorer.aptoslabs.com/?network=devnet
將右上角的網路選擇 Devnet,用回傳結果裡的 transaction_hash
搜尋,會看到 transaction 細節。
也可以直接點擊這個網址進行確認,但需要將帳號和 respurce 都改為你的 sender address
https://fullnode.devnet.aptoslabs.com/v1/accounts/0x1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c/resource/0x1fb73a71d8726aec382053d8c845903122d8e0a07922deea9553da6ee8835b3c::user_info::UserProfile
完美! 恭喜大家邁向 Move 一大步了,雖然筆者不小心在第五天忘記上傳文章導致賽事中斷,但還是很開心這 30 天有大家的陪伴,有任何問題都歡迎留言。