web3
# 小玩web3应用
web3是一个去中心化的区块链应用,它是一个更开放的世界,所有人可以参与,涉及到加密货币,智能合约等多个领域。 web3更安全,不依赖第三方平台,每个用户都会有一个唯一的身份----秘钥。切记,当这个秘钥丢失了,身份也就丢失了,再也找不回来。
# 参与web3
- 选择一个安全的加密货币钱包,例如metamask,okx欧易等;要保持好助记词或者秘钥,丢了就找不回来了
- 在币安,gate等交易所购买加密货币,然后跨链到钱包;
- 参与社区和项目;项目方在测试网阶段就会让所有人参与进来,玩家可以通过加密货币或者做任务,对Dapp进行交互
- 等项目方上交易所了就会发行代币,代币可以等值与美金
# web3开发
- 必备一定的计算机知识和一些开发语言
- 可以开发一些智能合约;
- 部署验证节点和data节点
# 玩了一下0Gchaind网络,部署了一个验证节点,体验一下web3
# 通过 CLI 安装 0gchaind
git clone -b v0.1.0 https://github.com/0glabs/0g-chain.git
./0g-chain/networks/testnet/install.sh
source ~/.profile
1
2
3
2
3
# 安装环境变量
echo export MONIKER=My_Node >> ~/.bash_profile
echo export CHAIN_ID=zgtendermint_16600-1 >> ~/.bash_profile
echo export WALLET_NAME=wallet >> ~/.bash_profile
echo export RPC_PORT=26657 >> ~/.bash_profile
source $HOME/.bash_profile
1
2
3
4
5
2
3
4
5
# 初始化节点
cd $HOME
0gchaind init $MONIKER --chain-id $CHAIN_ID
0gchaind config chain-id $CHAIN_ID
0gchaind config node tcp://localhost:$RPC_PORT
0gchaind config keyring-backend os
1
2
3
4
5
2
3
4
5
# 下载 genesis.json
sudo apt install -y unzip wget
rm ~/.0gchain/config/genesis.json
wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.1.0/genesis.json
1
2
3
2
3
# 验证genesis配置文件的正确性
0gchaind validate-genesis
1
# 添加种子节点和对等节点
PEERS="1248487ea585730cdf5d3c32e0c2a43ad0cda973@peer-zero-gravity-testnet.trusted-point.com:26326" && \
SEEDS="c4d619f6088cb0b24b4ab43a0510bf9251ab5d7f@54.241.167.190:26656,44d11d4ba92a01b520923f51632d2450984d5886@54.176.175.48:26656,f2693dd86766b5bf8fd6ab87e2e970d564d20aff@54.193.250.204:26656,f878d40c538c8c23653a5b70f615f8dccec6fb9f@18.166.164.232:26656" && \
sed -i -e "s/^seeds *=.*/seeds = \"$SEEDS\"/; s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $HOME/.0gchain/config/config.toml
1
2
3
2
3
# 设置最小gas费
sed -i "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0.00252ua0gi\"/" $HOME/.0gchain/config/app.toml
1
# 创建服务文件
tee /etc/systemd/system/ogd.service > /dev/null <<EOF
[Unit]
Description=OG Node
After=network.target
[Service]
User=$USER
Type=simple
ExecStart=$(which 0gchaind) start --home $HOME/.0gchain
Restart=on-failure
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 运行服务节点
systemctl daemon-reload && \
systemctl enable ogd && \
systemctl restart ogd && \
journalctl -u ogd -f -o cat
1
2
3
4
5
2
3
4
5
# 创建一个验证节点钱包
0gchaind keys add $WALLET_NAME --eth
1
# 获取EVM钱包地址
# 领水吧
echo "0x$(0gchaind debug addr $(0gchaind keys show $WALLET_NAME -a) | grep hex | awk '{print $3}')"
1
2
2
# 生成私钥可以添加到小狐狸钱包
0gchaind keys unsafe-export-eth-key $WALLET_NAME
1
# 查看节点同步状态
# 看catching_up是否为false,如果是,则同步完成,等吧
0gchaind status
1
2
2
# 通过下载快照加快同步 (这个废弃吧,尝试了,脚本跑不起来,没精力debug)
# 从端点下载最新的快照
wget https://rpc-zero-gravity-testnet.trusted-point.com/latest_snapshot.tar.lz4
# 停止ogd节点
sudo systemctl stop ogd
# 备份priv_validator_state.json
cp $HOME/.0gchain/data/priv_validator_state.json $HOME/.0gchain/priv_validator_state.json.backup
# 重置数据库
0gchaind tendermint unsafe-reset-all --home $HOME/.0gchain --keep-addr-book
# 从arvhive中提取文件
lz4 -d -c ./latest_snapshot.tar.lz4 | tar -xf - -C $HOME/.0gchain
# 将 priv_validator_state.json 移回
mv $HOME/.0gchain/priv_validator_state.json.backup $HOME/.0gchain/data/priv_validator_state.json
# 重启节点
sudo systemctl restart ogd && sudo journalctl -u ogd -f -o cat
# 检查同步状态
0gchaind status | jq .SyncInfo
# 快照每 3 小时更新一次
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 创建验器
# 要等区块链高度同步一致才创建验证器
0gchaind tx staking create-validator \
--amount=1000000ua0gi \
--pubkey=$(0gchaind tendermint show-validator) \
--moniker=$MONIKER \
--chain-id=$CHAIN_ID \
--commission-rate=0.05 \
--commission-max-rate=0.10 \
--commission-max-change-rate=0.01 \
--min-self-delegation=1 \
--from=$WALLET_NAME \
--identity="" \
--website="" \
--details="0G to the moon!" \
--gas=500000 --gas-prices=99999ua0gi \
-y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 检查它是否在验证器集中
0gchaind q staking validators -o json --limit=1000 | jq '.validators[] | select(.status=="BOND_STATUS_BONDED")' | jq -r '.tokens + " - " + .description.moniker' | sort -gr | nl
# 文档说只有排名前 125 名的质押验证者才会被选为活跃验证者,待看
1
2
2
# 质押
# 获取质押的验证者地址
0gchaind keys show $WALLET_NAME --bech val -a
# 质押代币
0gchaind tx staking delegate <质押的验证者地址> <不能大于钱包的0G>ua0gi --from $WALLET_NAME --gas=500000 --gas-prices=99999ua0gi -y
1
2
3
4
2
3
4
# 查询钱包余额
0gchaind q bank balances $(0gchaind keys show $WALLET_NAME -a)
1
# 在钱包之间发生代币
0gchaind tx bank send $WALLET_NAME <TO_WALLET> <AMOUNT>ua0gi --gas=500000 --gas-prices=99999ua0gi -y
1
# 查看验证器信息
访问网址:https://explorer.validatorvn.com/0G-Testnet/staking 搜索验证器地址就看到验证器信息
# 万一您的验证器被关进监狱,请使用此命令将其解锁
0gchaind tx slashing unjail --from $WALLET_NAME --gas=500000 --gas-prices=99999neuron -y
1