Creating a Local Binance DEX Testnet
Using a local dev environment provides needed testing flexibility
The Binance public testnet at https://testnet-explorer.binance.org is useful for testing DApps and other Binance-based applications. However, limitations include:
  • Issuing test tokens costs 500BNB
  • Listing test tokens costs 1000 BNB
  • ​Testnet Faucet only issues 200BNB once per address. If you want to test a full scale application you spend a lot of time acquiring and transferring tokens.
Creating a local dev testnet provides the opportunity to fully test an application without paying fees or visiting the faucet. We provide the necessary steps below.
Following the tutorial, there are instructions to move these commands to Docker.​

Run Binance Testnet Node

1) Download Required Binaries

All binaries are stored in the official GitHub repository (https://github.com/binance-chain/node-binary). Required are the latest versions of testnet fullnode and testnet cli.
In this tutorial, we use the following executables:
  • fullnode/testnet/0.6.2/linux/bnbchaind
  • cli/testnet/0.6.2/linux/tbnbcli
Install Git-LFS (used by the repository) and execute the following:
1
$ mkdir binance-testnet
2
$ cd binance-testnet
3
$ git clone --depth 1 https://github.com/binance-chain/node-binary.git
4
$ cd node-binary
5
$ git lfs pull -I fullnode/testnet/0.6.2/linux
6
$ git lfs pull -I cli/testnet/0.6.2/linux
7
$ cp ./node-binary/fullnode/testnet/0.6.2/linux/bnbchaind ./bnbchaind
8
$ cp ./node-binary/cli/testnet/0.6.2/linux/tbnbcli ./tbnbcli
Copied!
If you experience this error: "Skipping object checkout, Git LFS is not installed" run git lfs install again and rerun the git lfs pull command.

2) Generate Configs

Create all required configs for testnet validator, genesis block, etc
1
$ ./bnbchaind testnet --acc-prefix tbnb --chain-id Binance-Dev --v 1
Copied!
  • --acc-prefix defines used binance BECH32 addresses prefix ()
  • tbnb used for consistency with public testnet
  • --v denotes an initial number of validators for the Binance Chain, put it 1 for simplicity.
Generated configs will be located in the ./mytestnet/node0/gaiad/config directory. Important files are app.toml, config.toml, genesis.json.
If needed, modify parameters in these files (for example settingBEP12Height = 1 in app.toml will allow BEP12 transactions from the first block).

3) Start Validator Full Node

All necessary files (chain configs and validator account keys) are located in the./mytestnet/node0/gaiad directory.
1) Start validator node
1
$ ./bnbchaind start --home ./mytestnet/node0/gaiad
Copied!
Validator node should start generating new blocks, which can be observed through the terminal.
The error message "Couldn't connect to any seeds module=p2p" in the terminal window is expected behavior.
2) Node validator automatically provides Node-RPC service at http://localhost:26657. Check it out using /status sub-url from a second terminal window.
1
$ curl -s -X GET http://localhost:26657/status | jq
Copied!

4): Create a Prefunded Address

At the moment, a single validator account exists in the network. Let’s create another one, and prefund it for future use.
1
$ echo password | ./tbnbcli keys add test-acc --no-backup
2
NAME: TYPE: ADDRESS: PUBKEY:
3
test-acc local tbnb1n5d0n9avv3svhe5sd56nt63yygrn794uu6jvdk bnbp1addwnpepqd0xp73y09yvlk4p5csmzmpu7lwpxg9da9vkkm52d2sqtazylwwtx4dt2xwjwqtq
Copied!
Note the printed account address. We will transfer BNB tokens from the validator account to our newly created one.
1
$ echo 12345678 | ./tbnbcli send \
2
--chain-id Binance-Dev \
3
--to tbnb1n5d0n9avv3svhe5sd56nt63yygrn794uu6jvdk \
4
--amount "10000000000000:BNB" \
5
--from node0 \
6
--home ./mytestnet/node0/gaiacli \
7
--json
Copied!
  • --to previously generated address
  • --from validator node key name (by default node0)
  • --home - directory with validator keystore files
  • 12345678 - default password for validator keystore.

Additional Actions

Now you can continue with regular binance dex actions. For example, issue a new token:
1
$ echo password | ./tbnbcli token issue \
2
--chain-id Binance-Dev \
3
--symbol DEV \
4
--total-supply 10000000000000000 \
5
--token-name "DEV Token" \
6
--from test-acc
Copied!

Accessible HTTP API Services

In regular binance mainnet and testnet, three different APIs are available:
  • ​Node RPC - in our Binance-Dev network it is accessible at http://localhost:26657
  • ​Api-server - in our testnet, instantiate by running ./tbnbcli api-server --chain-id Binance-Dev
  • ​HTTP-API - api of the accelerated node is not accessible. There is no way to make your accelerated node, so this api will not work. However, some paths can be covered by the first two api services, or emulated if necessary.

Moving to Docker

Dockerfile for fetching binaries and updating configs

1
FROM ubuntu:19.10
2
​
3
ARG BNC_VERSION=0.6.2
4
​
5
RUN apt-get update && \
6
apt-get install -y git git-lfs
7
​
8
WORKDIR /binaries
9
​
10
RUN git clone --depth 1 https://github.com/binance-chain/node-binary.git .
11
​
12
RUN git lfs pull -I fullnode/testnet/${BNC_VERSION}/linux
13
RUN git lfs pull -I cli/testnet/${BNC_VERSION}/linux
14
​
15
RUN ./fullnode/testnet/${BNC_VERSION}/linux/bnbchaind testnet --acc-prefix tbnb --chain-id Binance-Dev --v 1
16
​
17
RUN sed -i "s/BEP12Height = 9223372036854775807/BEP12Height = 1/" ./mytestnet/node0/gaiad/config/app.toml
Copied!
Assume that image built from this file is called testnet-binaries

Dockerfile for Validator Node

1
FROM alpine:3.9.4
2
​
3
ARG BNC_VERSION=0.6.2
4
​
5
WORKDIR /bnc
6
​
7
COPY --from=testnet-binaries /binaries/fullnode/testnet/${BNC_VERSION}/linux/bnbchaind ./
8
COPY --from=testnet-binaries /binaries/cli/testnet/${BNC_VERSION}/linux/tbnbcli ./
9
COPY --from=testnet-binaries /binaries/mytestnet/node0/gaiacli /root/.bnbcli
10
COPY --from=testnet-binaries /binaries/mytestnet/node0/gaiad /root/.bnbchaind
11
​
12
EXPOSE 26657
13
​
14
ENTRYPOINT ["./bnbchaind", "start"]
Copied!

Dockerfile for API-Server

1
FROM alpine:3.9.4
2
​
3
ARG BNC_VERSION=0.6.2
4
​
5
WORKDIR /api-server
6
​
7
COPY --from=testnet-binaries /binaries/cli/testnet/${BNC_VERSION}/linux/tbnbcli ./
8
​
9
RUN echo 12345678 | ./tbnbcli keys add key
10
​
11
EXPOSE 8080
12
​
13
ENTRYPOINT ["./tbnbcli", "api-server", "--chain-id", "Binance-Dev", "--laddr", "tcp://0.0.0.0:8080", "--node"]
Copied!

docker-compose.yml

1
version: '3.0'
2
services:
3
node:
4
build: node
5
image: bnc-node
6
networks:
7
- binance_rpc_net
8
ports:
9
- '26657:26657'
10
volumes:
11
- 'binance_data:/root/.bnbchaind/data'
12
api-server:
13
build: api-server
14
image: bnc-api-server
15
networks:
16
- binance_rpc_net
17
ports:
18
- '8080:8080'
19
command: ["http://node:26657"]
20
networks:
21
binance_rpc_net:
22
volumes:
23
binance_data:
Copied!
​
Last modified 1yr ago