OpenBuild Starknet Bootcamp 任务2:Ownable合约部署、所有权转移、dispatcher交互

  • rzexin
  • 更新于 2023-12-17 23:31
  • 阅读 2000

基于Ownable contract在 testnet 上用不同的钱包(argent 和 braavos)部署 2 个智能合约。将合约所有权从 argent 钱包账户转移到 braavos 账户。与 dispatcher 交互,从智能合约 1 调用智能合约 2 的数据。

OpenBuild Starknet Bootcamp 任务2:Ownable合约部署、所有权转移、dispatcher交互

1 任务要求

基于 Ownable contract,在 testnet 上用不同的钱包(argent 和 braavos)部署 2 个智能合约。将合约所有权从 argent 钱包账户转移到 braavos 账户。与 dispatcher 交互,从智能合约 1 调用智能合约 2 的数据。

2 钱包准备

2.1 创建钱包

钱包 地址
Argent 0x05E51CAF456A394D4ED02c4e0f373d8A162851c492d382F74822b10AaD11300d
Braavos 0x00b05390123e1e3749ae040834342eefd541f96e210b50f4ff6de8e8dd37b08d

2.2 跨链转账or领水

https://goerli.starkgate.starknet.io/

image.png

https://faucet.goerli.starknet.io/

image.png

image.png

2.3 部署帐号

image.png

2.4 钱包准备

(1)导入私钥

$ mkdir ~/.wallets

# ArgentX
$ starkli signer keystore from-key ~/.wallets/a_keystore.json
Enter private key: 
Enter password: 
Created new encrypted keystore file: /root/.wallets/a_keystore.json
Public key: 0x01ee7e9a91785e30a72b492cc17e2842fc6fc1ae5d25f922a174fab0bbb870e6

# Braavos
$ starkli signer keystore from-key ~/.wallets/b_keystore.json
Enter private key: 
Enter password: 
Created new encrypted keystore file: /root/.wallets/b_keystore.json
Public key: 0x053dba779be838414eaf38356c59b26d63846e5a0ac4d1f9e5ae6725b8c052e8

(2)创建账户描述

# ArgentX
$ starkli account fetch 0x05E51CAF456A394D4ED02c4e0f373d8A162851c492d382F74822b10AaD11300d --output ~/.wallets/a_account.json --rpc https://starknet-goerli.g.alchemy.com/v2/xxx
Account contract type identified as: Argent X
Description: Argent X official account
Downloaded new account config file: /root/.wallets/a_account.json

# Braavos
starkli account fetch 0x00b05390123e1e3749ae040834342eefd541f96e210b50f4ff6de8e8dd37b08d --output ~/.wallets/b_account.json --rpc https://starknet-goerli.g.alchemy.com/v2/xxx
Account contract type identified as: Braavos
Description: Braavos official proxy account
Downloaded new account config file: /root/.wallets/b_account.json

3 合约部署

3.1 合约编译

$ scarb build
   Compiling cairo1_v2 v0.1.0 (/root/Ownable-Starknet/Scarb.toml)
    Finished release target(s) in 1 second

3.2 准备env

  • .env_a
export STARKNET_RPC="https://starknet-goerli.g.alchemy.com/v2/xxx"
export STARKNET_ACCOUNT="/root/.wallets/a_account.json"
export STARKNET_KEYSTORE="/root/.wallets/a_keystore.json"
  • .env_b
export STARKNET_RPC="https://starknet-goerli.g.alchemy.com/v2/xxx"
export STARKNET_ACCOUNT="/root/.wallets/b_account.json"
export STARKNET_KEYSTORE="/root/.wallets/b_keystore.json"

3.3 声明合约

$ starkli declare target/dev/cairo1_v2_ownable.contract_class.json --compiler-version 2.4.0
Enter keystore password: 
Declaring Cairo 1 class: 0x00f6e62159da1635ccd0fe7b26a5b64d499138bb47718cdbb3dab5d5c5258e85
Compiling Sierra class to CASM with compiler version 2.4.0...
CASM class hash: 0x01cf30830a36b80f72e5a6da74186f5a9ffcee82806307c5be8316881dd4598c
Contract declaration transaction: 0x010dcf70544bdc3f97c9904da6b929ce2a12bee561c8166e008dda8ee658fc25
Class hash declared:
0x00f6e62159da1635ccd0fe7b26a5b64d499138bb47718cdbb3dab5d5c5258e85

3.4 部署合约

# ArgentX
$ source .env_a
$ starkli deploy 0x00f6e62159da1635ccd0fe7b26a5b64d499138bb47718cdbb3dab5d5c5258e85 0x05E51CAF456A394D4ED02c4e0f373d8A162851c492d382F74822b10AaD11300d
Enter keystore password: 
Deploying class 0x00f6e62159da1635ccd0fe7b26a5b64d499138bb47718cdbb3dab5d5c5258e85 with salt 0x04360e936156b80eba7a53295668aff3d44e977a077624c8bdd9e732159d9258...
The contract will be deployed at address 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed
Contract deployment transaction: 0x052464aa888794d3af81916244646a9af2e030ea1b6ecf4ca1f6231ac9f5856f
Contract deployed:
0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed

# Braavos
$ source .env_b
$ starkli deploy 0x00f6e62159da1635ccd0fe7b26a5b64d499138bb47718cdbb3dab5d5c5258e85 0x00b05390123e1e3749ae040834342eefd541f96e210b50f4ff6de8e8dd37b08d
Enter keystore password: 
Deploying class 0x00f6e62159da1635ccd0fe7b26a5b64d499138bb47718cdbb3dab5d5c5258e85 with salt 0x05e24d42dd82fcff86e3341a6b4f944e781502e5792a15e63df468924955cebb...
The contract will be deployed at address 0x05596ddf0008770dd195d7ab22778be5362b61e1f3519f1bd7efba4fb7f2b210
Contract deployment transaction: 0x0734d968d80a92c96ca34fb27e378991461c27552ebc57b12360a386a7948e8e
Contract deployed:
0x05596ddf0008770dd195d7ab22778be5362b61e1f3519f1bd7efba4fb7f2b210

4 合约调测

4.1 获取钱包所有者

$ starkli call 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed read_owner
[
    "0x05e51caf456a394d4ed02c4e0f373d8a162851c492d382f74822b10aad11300d"
]

$ starkli call 0x05596ddf0008770dd195d7ab22778be5362b61e1f3519f1bd7efba4fb7f2b210 read_owner
[
    "0x00b05390123e1e3749ae040834342eefd541f96e210b50f4ff6de8e8dd37b08d"
]

image.png

4.2 ArgentX帐号成功修改自己的数据

$ starkli invoke 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed set_data 0x123
Enter keystore password: 
Invoke transaction: 0x00af0f349edcaba005ba7ec25959fdb5282d2c474b2647a2c382dd63609c4f0b

$ starkli call 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed get_data
[
    "0x0000000000000000000000000000000000000000000000000000000000000123"
]

image.png

4.3 Braavos帐号修改ArgentX帐号的数据失败

$ starkli call 0x05596ddf0008770dd195d7ab22778be5362b61e1f3519f1bd7efba4fb7f2b210 other_func 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed
[
    "0x0000000000000000000000000000000000000000000000000000000000000123"
]

$ starkli invoke 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed set_data 0x456
Enter keystore password: 
Error: code=ContractError, message="Contract error"

image.png

4.4 ArgentX帐号将所有权转移给Braavos帐号

# 转移前帐号归属
$ starkli call 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed read_owner
[
    "0x05e51caf456a394d4ed02c4e0f373d8a162851c492d382f74822b10aad11300d"
]

# 转移帐号所有权
$ starkli invoke 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed transfer_ownership 0x00b05390123e1e3749ae040834342eefd541f96e210b50f4ff6de8e8dd37b08d
Enter keystore password: 
Invoke transaction: 0x06035e529d6f9cd973a78334a60825c22fe8872f1492825fcb50d90bd7728405

# 转移后帐号归属
$ starkli call 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed read_owner
[
    "0x00b05390123e1e3749ae040834342eefd541f96e210b50f4ff6de8e8dd37b08d"
]

image.png

4.5 Braavos帐号再次修改ArgentX帐号的数据成功

$ starkli invoke 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed set_data 0x456
Enter keystore password: 
Invoke transaction: 0x05d96084aa237aceab74030ce187e4ccc1d97fb7f62fc6d3c3dd447ab9aeb8f6

$ starkli call 0x05596ddf0008770dd195d7ab22778be5362b61e1f3519f1bd7efba4fb7f2b210 other_func 0x007c7ccc869c2fbbb1145b96ae1f499c493503fecf953349614030c78bd38eed
[
    "0x0000000000000000000000000000000000000000000000000000000000000456"
]

image.png

点赞 1
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
rzexin
rzexin
0x6Fa5...8165
江湖只有他的大名,没有他的介绍。