配置环境(下载链接参考主页

下载scarb 2.3.1

下载starknet-foundry-rs 0.10.2

bin目录加入环境变量,并验证

scarb --version
snforge --version

创建项目

snforge init x0_contracts

Untitled

项目配置

Scarb.toml配置如下:

简化执行命令,省略默认参数

指定合约名称和路径

指定账户默认为test_user_0,交易默认由此账户发起

指定默认url(替换为测试网络rpc

[package]
name = "x0_contracts"
version = "0.1.0"

# See more keys and their definitions at <https://docs.swmansion.com/scarb/docs/reference/manifest.html>

[dependencies]
snforge_std = { git = "<https://github.com/foundry-rs/starknet-foundry>", tag = "v0.10.2" }
starknet = "2.3.1"

[[target.starknet-contract]]
casm = true
HelloStarknet = { path = "src/lib" }
# foo = { path = "vendor/foo" }

[tool.sncast]
account = "test_user_0" 
accounts-file = "accounts.json"
# url = "<http://127.0.0.1:5050/rpc>"
url = "<https://starknet-goerli.g.alchemy.com/v2/66iTEsBmPgN2fNIeNLf90oTg---->"

初始化账户文件

创建两个账号

sncast account create -n test_user_0

sncast account create -n test_user_1

根目录下会创建accounts.json文件,打开可以看到两个密钥信息(这是我的,你的肯定不一样)

test_user_0:0x3180b441f524c2de2515094fc85ffef278d9764f6ebbb87db68928c094177ff

test_user_1:0xdc64f74f50383703de669eb9dd4b7eb7f6ecbc792f34232112193c6ed86d9a

部署账户合约

starknet网络转测试eth到这两个账户地址上(否则不能部署账户合约)

eth到账后可部署两个账户合约到starknet网络

test_user_0和test_user_1为accounts.json中账户名

sncast account deploy --name test_user_0 --max-fee 8646000000000
sncast account deploy --name test_user_1 --max-fee 8646000000000