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.
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
$ mkdir binance-testnet
$ cd binance-testnet
$ git clone --depth 1 https://github.com/binance-chain/node-binary.git
$ cd node-binary
$ git lfs pull -I fullnode/testnet/0.6.2/linux
$ git lfs pull -I cli/testnet/0.6.2/linux
$ cp ./node-binary/fullnode/testnet/0.6.2/linux/bnbchaind ./bnbchaind
$ cp ./node-binary/cli/testnet/0.6.2/linux/tbnbcli ./tbnbcli
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.Create all required configs for testnet validator, genesis block, etc
$ ./bnbchaind testnet --acc-prefix tbnb --chain-id Binance-Dev --v 1
--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 it1
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 setting
BEP12Height = 1
in app.toml
will allow BEP12 transactions from the first block).All necessary files (chain configs and validator account keys) are located in the
./mytestnet/node0/gaiad
directory.1) Start validator node
$ ./bnbchaind start --home ./mytestnet/node0/gaiad
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.$ curl -s -X GET http://localhost:26657/status | jq
At the moment, a single validator account exists in the network. Let’s create another one, and prefund it for future use.
$ echo password | ./tbnbcli keys add test-acc --no-backup
NAME: TYPE: ADDRESS: PUBKEY:
test-acc local tbnb1n5d0n9avv3svhe5sd56nt63yygrn794uu6jvdk bnbp1addwnpepqd0xp73y09yvlk4p5csmzmpu7lwpxg9da9vkkm52d2sqtazylwwtx4dt2xwjwqtq
Note the printed account address. We will transfer BNB tokens from the validator account to our newly created one.
$ echo 12345678 | ./tbnbcli send \
--chain-id Binance-Dev \
--to tbnb1n5d0n9avv3svhe5sd56nt63yygrn794uu6jvdk \
--amount "10000000000000:BNB" \
--from node0 \
--home ./mytestnet/node0/gaiacli \
--json
--to
previously generated address--from
validator node key name (by defaultnode0
)--home
- directory with validator keystore files12345678
- default password for validator keystore.
Now you can continue with regular binance dex actions. For example, issue a new token:
$ echo password | ./tbnbcli token issue \
--chain-id Binance-Dev \
--symbol DEV \
--total-supply 10000000000000000 \
--token-name "DEV Token" \
--from test-acc
In regular binance mainnet and testnet, three different APIs are available:
- 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.
FROM ubuntu:19.10
ARG BNC_VERSION=0.6.2
RUN apt-get update && \
apt-get install -y git git-lfs
WORKDIR /binaries
RUN git clone --depth 1 https://github.com/binance-chain/node-binary.git .
RUN git lfs pull -I fullnode/testnet/${BNC_VERSION}/linux
RUN git lfs pull -I cli/testnet/${BNC_VERSION}/linux
RUN ./fullnode/testnet/${BNC_VERSION}/linux/bnbchaind testnet --acc-prefix tbnb --chain-id Binance-Dev --v 1
RUN sed -i "s/BEP12Height = 9223372036854775807/BEP12Height = 1/" ./mytestnet/node0/gaiad/config/app.toml
Assume that image built from this file is called
testnet-binaries
FROM alpine:3.9.4
ARG BNC_VERSION=0.6.2
WORKDIR /bnc
COPY --from=testnet-binaries /binaries/fullnode/testnet/${BNC_VERSION}/linux/bnbchaind ./
COPY --from=testnet-binaries /binaries/cli/testnet/${BNC_VERSION}/linux/tbnbcli ./
COPY --from=testnet-binaries /binaries/mytestnet/node0/gaiacli /root/.bnbcli
COPY --from=testnet-binaries /binaries/mytestnet/node0/gaiad /root/.bnbchaind
EXPOSE 26657
ENTRYPOINT ["./bnbchaind", "start"]
FROM alpine:3.9.4
ARG BNC_VERSION=0.6.2
WORKDIR /api-server
COPY --from=testnet-binaries /binaries/cli/testnet/${BNC_VERSION}/linux/tbnbcli ./
RUN echo 12345678 | ./tbnbcli keys add key
EXPOSE 8080
ENTRYPOINT ["./tbnbcli", "api-server", "--chain-id", "Binance-Dev", "--laddr", "tcp://0.0.0.0:8080", "--node"]
version: '3.0'
services:
node:
build: node
image: bnc-node
networks:
- binance_rpc_net
ports:
- '26657:26657'
volumes:
- 'binance_data:/root/.bnbchaind/data'
api-server:
build: api-server
image: bnc-api-server
networks:
- binance_rpc_net
ports:
- '8080:8080'
command: ["http://node:26657"]
networks:
binance_rpc_net:
volumes:
binance_data:
Last modified 3yr ago