操作系統(tǒng):MAC OS 10.14.x
zksync:https://github.com/matter-labs/zksync,master 分支
commit 899ca93052420c33583755cd2162143f461f36b3
需要注意的是烫罩,閱讀完整源代碼需要查看dev分支挽封,master分支是提供編譯后的各種執(zhí)行程序好芭。在以下安裝時进萄,請科學(xué)上網(wǎng)塔粒。
環(huán)境準(zhǔn)備 zksync/docs/setup-dev.md
1糖声、安裝docker
brew cask install docker
2抽莱、安裝Node & Yarn
brew install nodejs yarn
3、Axel
brew install axel
axel版本有差異纸型,請采用axel 2.17.X拇砰,ubuntu、centos7狰腌、8環(huán)境除破,axel2.4、2.5版本均有問題癌别,主要體現(xiàn)在執(zhí)行:cargo install diesel_cli --no-default-features --features postgres無法通過皂岔。
4蹋笼、Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustc --version
rustc 1.46.0 (04488afe3 2020-08-24)
5展姐、postgresql
brew install postgresql
6躁垛、Diesel cli
cargo install diesel_cli --no-default-features --features postgres
過程比較慢,耐心等待圾笨。教馆。。
7擂达、sqlx cli
cargo install sqlx-cli
8土铺、solc
必須是v0.5.X
brew install solidity@5
9、下載zksync
git clone https://github.com/matter-labs/zksync.git
10板鬓、編輯~/. bash_profile:
export ZKSYNC_HOME=/path/to/zksync
export PATH=$ZKSYNC_HOME/bin:$PATH
到這里悲敷,環(huán)境依賴已經(jīng)完成了
啟動zksync zksync/docs/launch.md
1、設(shè)置本地運行環(huán)境
cd zksync/bin && ./zk #installs and builds zk itself
zk init #時間會比較久俭令,耐心等待需要下載約8G的電路設(shè)置文件
初始化只需要一次即可后德,查看infrastructure/zk/src/init.ts
export async function init() {
if (!process.env.CI) {
await checkEnv();
await env.gitHooks();
await up();
}
await utils.allowFail(run.yarn());
await run.plonkSetup();
await run.verifyKeys.unpack();
await db.setup();
await contract.buildDev();
await run.deployERC20('dev');
await contract.build();
await server.genesis();
await contract.redeploy();
}
2、啟動容器
zk up
查看infrastructure/zk/src/up.ts
,該命令啟動了geth 1抄腔,postgres瓢湃,dev-ticker,tesseracts
export async function up() {
await utils.spawn('docker-compose up -d postgres geth dev-ticker');
await utils.spawn('docker-compose up -d tesseracts');
}
退出容器
zk down
3赫蛇、運行zksync server
$ zk server
Finished release [optimized] target(s) in 1.28s
Running `target/release/zksync_server`
[2020-12-07T06:23:10Z INFO zksync_server] Running the zkSync server
[2020-12-07T06:23:10Z INFO zksync_server] Starting the Core actors
[2020-12-07T06:23:10Z INFO zksync_core::state_keeper] Loaded committed state: last block number: 8, unprocessed priority op: 4
[2020-12-07T06:23:10Z INFO zksync_core::state_keeper] created state keeper, root hash = Fr(0x2e1da2ec83289a3bb50282b56dee671ff815ac520f5a64c2ce89f3e62284a7dc)
[2020-12-07T06:23:10Z INFO zksync_core::state_keeper] Executed restored proposed block: 0 transactions, 0 priority operations, 0 failed transactions
[2020-12-07T06:23:10Z INFO zksync_server] Starting the API server actors
[2020-12-07T06:23:10Z INFO zksync_server] Starting the Ethereum sender actors
[2020-12-07T06:23:10Z INFO zksync_server] Starting the Prover server actors
[2020-12-07T06:23:10Z INFO zksync_witness_generator] Starting witness generator (1,2)
[2020-12-07T06:23:10Z INFO zksync_witness_generator::witness_generator] preparing prover data routine started with start_block(1), block_step(2)
[2020-12-07T06:23:10Z INFO zksync_witness_generator] Starting witness generator (2,2)
[2020-12-07T06:23:10Z INFO zksync_witness_generator::witness_generator] preparing prover data routine started with start_block(2), block_step(2)
[2020-12-07T06:23:10Z INFO zksync_core::mempool] 0 transactions were restored from the persistent mempool storage
第一次運行會編譯rust绵患,時間比較久,請耐心等待
查看infrastructure/zk/src/server.ts
悟耘,用ts來編譯落蝙、運行了core/bin/server/src/main.rs
。
export async function server() {
await utils.spawn('cargo run --bin zksync_server --release');
}
關(guān)于etc/env/dev.env
這個文件是在init的時候從dev.env.example復(fù)制生成的作煌【蚺梗可以修改其中的參數(shù),
如端口參數(shù)粟誓、出塊間隔奏寨、見證者數(shù)量等。在本地的部署測試中鹰服,發(fā)現(xiàn)zk server
的時候端口被占用的錯誤病瞳,首先請排查端口占用情況:lsof -i:8545
,如果沒有占用情況,那可以修改dev.env的端口在嘗試一下悲酷。有需要的話套菜,需要同步修改etc/js/env-config.js
的端口。
4设易、運行zksync cli
cd bin && vim zcli #拷貝zk文件內(nèi)容逗柴,作出相應(yīng)修改
zcli文件內(nèi)容:
#!/bin/bash
if [ -z "$1" ]; then
cd $ZKSYNC_HOME
yarn && yarn zcli build
else
# can't start this with yarn since it has quirks with `--` as an argument
node -- $ZKSYNC_HOME/infrastructure/zcli/build/index.js "$@"
fi
$ ./zcli #build xcli
$ zcli -h #查看命令行幫助
Usage: zcli [options] [command]
Options:
-V, --version output the version number
-n, --network <network> select network (default: "localhost")
-h, --help display help for command
Commands:
account [address] view account info
transaction <tx_hash> view transaction info
transfer [options] [amount] [token] [recipient] make a transfer
deposit [options] [amount] [token] [recipient] make a deposit
await [options] <type> <tx_hash> await for transaction commitment/verification
networks view configured networks
wallets view saved wallets
help [command] display help for command
添加賬號:
$ zcli wallets add 0x27593fea79697e947890ecbecce7901b0008345e5d7259710d0dd5e500d040be
[WARNING]: private keys are stored unencrypted
"0xde03a0B5963f75f1C8485B355fF6D30f3093BDE7"
$ zcli wallets default 0xde03a0b5963f75f1c8485b355ff6d30f3093bde7
"0xde03a0b5963f75f1c8485b355ff6d30f3093bde7"
$ zcli wallets
[
"0xde03a0b5963f75f1c8485b355ff6d30f3093bde7",
"0xab9fc101e0958669c92d71855f41aa5c949e5d8e",
"0xdb850fd6dd80f0f689f2f4671a003c99ed73cd49"
]
$ zcli account 0xde03a0b5963f75f1c8485b355ff6d30f3093bde7
{
"address": "0xde03a0b5963f75f1c8485b355ff6d30f3093bde7",
"network": "localhost",
"account_id": 0,
"nonce": 0,
"balances": {
"ETH": "0.0004132"
}
}
$ zcli deposit 1000 ETH 0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE --fast
"0x39e8a769a1be699c01afad650f3d5ff3c570bb805a9c7b23177080cff35c8ae5"
$ zcli transaction 0x39e8a769a1be699c01afad650f3d5ff3c570bb805a9c7b23177080cff35c8ae5
{
"network": "localhost",
"transaction": {
"status": "success",
"from": "0xde03a0b5963f75f1c8485b355ff6d30f3093bde7",
"to": "0x52312ad6f01657413b2eae9287f6b9adad93d5fe",
"hash": "0x39e8a769a1be699c01afad650f3d5ff3c570bb805a9c7b23177080cff35c8ae5",
"operation": "Deposit",
"nonce": -1,
"amount": "1000.0",
"token": "ETH"
}
}
$ zcli account 0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE
{
"address": "0x52312AD6f01657413b2eaE9287f6B9ADaD93D5FE",
"network": "localhost",
"account_id": 1,
"nonce": 5,
"balances": {
"ETH": "2994.9995868"
}
} #原先有抵押過了
$ zcli transfer 2 ETH 0xdB850fD6DD80f0F689F2f4671A003c99ed73cD49
...
0xde03a0B5963f75f1C8485B355fF6D30f3093BDE7
為dev.env文件中有L2給 geth1 發(fā)交易的地址,私鑰也在配置文件中顿肺。
大家可以按照提示使用zcli來向zksync發(fā)送交易戏溺,查詢交易等操作渣蜗。
日拱一卒!