跳转至

设置本地测试网(高级)

原文:https://docs.elrond.com/developers/setup-local-testnet-advanced

如何在工作站上建立本地Elrond测试网?

先决条件

首先,在你选择的目录中克隆埃尔隆-go埃尔隆-代理-go

$ mkdir mytestnet && cd mytestnet
$ git clone [email protected]:ElrondNetwork/elrond-go.git
$ git clone [email protected]:ElrondNetwork/elrond-proxy-go.git 

然后,运行prerequisites命令。

$ cd elrond-go/scripts/testnet
$ ./prerequisites.sh 

这将安装一些包并克隆 elrond-deploy-go 存储库,作为先前克隆的elrond-go的兄弟。

根据您的 Linux 发行版,您可能还需要运行以下命令:

sudo apt install tmux
sudo apt install gnome-terminal 

配置 Testnet

决定测试网结构的变量位于文件scripts/testnet/variables.sh中。例如:

export TESTNETDIR="$HOME/Elrond/testnet"
export SHARDCOUNT=2
... 

您可以通过创建一个名为local.sh的新文件来覆盖默认变量,作为variables.sh的兄弟。例如,为了使用不同于默认目录的目录:

local.sh
export TESTNETDIR="$HOME/Desktop/mytestnet/sandbox"
export USETMUX=1
export NODETERMUI=0 

一旦准备好覆盖所需的参数,运行config命令。

$ ./config.sh 

之后,您可以在指定的文件夹中检查生成的配置文件:

$HOME/Desktop/mytestnet/sandbox
├── filegen
│   ├── filegen
│   └── output
│       ├── delegationWalletKey.pem
│       ├── delegators.pem
│       ├── genesis.json
│       ├── genesisSmartContracts.json
│       ├── nodesSetup.json
│       ├── validatorKey.pem
│       └── walletKey.pem
├── node
│   └── config │       ├── api.toml
│       ├── config_observer.toml
│       ├── config_validator.toml
│       ├── delegationWalletKey.pem
│       ├── delegators.pem
│       ├── economics.toml
│       ├── external.toml
│       ├── gasSchedule.toml
│       ├── genesisContracts
│       │   ├── delegation.wasm
│       │   └── dns.wasm
│       ├── genesis.json
│       ├── genesisSmartContracts.json
│       ├── nodesSetup.json
│       ├── p2p.toml
│       ├── prefs.toml
│       ├── ratings.toml
│       ├── systemSmartContractsConfig.toml
│       ├── validatorKey.pem
│       └── walletKey.pem
├── node_working_dirs
├── proxy │   └── config │       ├── config.toml
│       ├── economics.toml
│       ├── external.toml
│       └── walletKey.pem
└── seednode
    └── config        ├── config.toml
        └── p2p.toml 

启动和停止 Testnet

为了启动测试网,运行start命令。

$ ./start.sh debug 

等待大约 1 分钟后,您可以检查文件夹mytestnet/sandbox/node_working_dirs中正在运行的节点的日志。

为了停止测试网络,运行stop命令。

$ ./stop.sh 

如果需要,您还可以pauseresumeTestnet(不实际停止运行的节点):

$ ./pause.sh
$ ./resume.sh 

重现测试网

为了破坏测试网,运行clean命令:

./stop.sh
./clean.sh 
清理后运行配置

运行 clean 之后,需要在启动之前运行 config ,以便再次启动 Testnet。

如果您需要从头开始重新创建一个测试网,使用reset命令(它也在幕后执行clean):

$ ./reset.sh 

检查代理

默认情况下,本地测试网还包括一个本地Elrond代理实例,监听端口 7950 。可以在浏览器中查询,也可以直接在命令行中查询。另请参见 REST API

$ curl http://localhost:7950/network/config 

根据上面的请求,从响应中提取并保存字段erd_chain_iderd_min_transaction_version。您将需要它们来根据您的本地 Testnet 发送交易。

配置 erdpy

默认情况下,您可以将 erdpy 配置为指向您的本地 Testnet:

$ erdpy config set chainID 15...
$ erdpy config set txVersion 123
$ erdpy config set proxy http://localhost:7950 

发送交易

让我们使用 erdpy: 发送一个简单的交易

$ erdpy tx new --recall-nonce --data="Hello, World" --gas-limit=70000 \
 --receiver=erd1... \
 --pem=./sandbox/node/config/walletKey.pem --pem-index=0 \
 --send 

您应该在stdout(或您选择的--outfile)中看到准备好的交易和交易散列。使用交易散列,您可以根据代理查询交易的状态:

$ curl http://localhost:7950/transaction/1363... 

部署智能合约并与之交互

让我们使用 erdpy 部署一个智能合约。我们将以简单的计数器为例。

Deploy
erdpy --verbose contract deploy --bytecode=./mycounter/output/counter.wasm \
 --recall-nonce --gas-limit=5000000 \
 --pem=./sandbox/node/config/walletKey.pem --pem-index=0 \
 --outfile=myCounter.json \
 --send 

部署后,您可以检查交易的状态以及智能合约是否存在:

$ curl http://localhost:7950/transaction/daf2...
$ curl http://localhost:7950/address/erd1qqqqqqqqqqqqqpgql... 

如果一切正常(交易状态为executed并且地址的code属性已设置),您可以与已部署的合约进行交互或对其执行查询:

Call
erdpy --verbose contract call erd1qqqqqqqqqqqqqpgql... \
 --recall-nonce --gas-limit=1000000 --function=increment \
 --pem=./sandbox/node/config/walletKey.pem --pem-index=0 --outfile=myCall.json \
 --send 
Query
erdpy --verbose contract query erd1qqqqqqqqqqqqqpgqlq... --function=get 


回到顶部