Host Your Own Testnet Faucet
I've been hosting the testnet faucet for months now. My experience is that it's the only testnet faucet for BCH now which is not very healthy.
The faucet software itself is an open source software and a fruit of a successful community funding. Also I have been blessed with the opportunity to work more on BCH projects.
Dockerfile
So I created a Docker file that allows anyone to host the faucet. I invite you to test the new software hosted on a Docker container on this address:
I'll move it to the main domain after some testing.
Improvements:
Better performance by using RPC for communication with Electron Cash
Using Template file instead of inline html
Built a Dockerfile so anyone can host a testnet faucet
Used Poetry package manager and pyproject.toml file
Challenges
EC wallet not allowing password-less wallet creation. I had to use
expect
to mitigate that, it took 9 lines of Dockerfile.Had some issues passing variables from environment variables to the software in a proper way that could make it run on a container or stand alone.
Had to learn many stuff about python and Docker :)
Help with Testing and Review
Docker file is available on the faucet repository under docker-support
branch currently, I'm posting it here for ease of view:
# syntax=docker/dockerfile-upstream:1-labs
FROM alpine:3.15
MAINTAINER uak@gitlab
EXPOSE 8080
ENV USER_HOME /home/user
ENV DATA_DIR "$USER_HOME"/data
ENV EC_DIR "$USER_HOME"/Electron-Cash
ENV faucet_conf "$DATA_DIR"/tbch_web.config
ENV cherrypy_conf "$DATA_DIR"/cherrypy.config
ENV wallet_path "$DATA_DIR"/testnet/wallets/default_wallet
ENV database_file "$DATA_DIR"/db.sqlite3
ENV use_custom_dir True
ENV allow_zero_balance True
ENV custom_dir "$DATA_DIR"
ENV network testnet
ENV ec_config "$DATA_DIR"/testnet/config
ENV rpc_port 10500
ENV rpc_url "http://127.0.0.1"
ENV web_access_log "$DATA_DIR"/access.log
ENV web_error_log "$DATA_DIR"/error.log
RUN apk update
RUN apk --no-cache upgrade
RUN apk add --no-cache python3 libsecp256k1-dev py3-pip logrotate
RUN apk add --no-cache git expect
RUN cat <<-EOF > /etc/logrotate.d/cherrypy
$DATA_DIR/*.log {
rotate 12
weekly
copytruncate
compress
missingok
}
EOF
RUN adduser user --disabled-password --gecos "" --home "$USER_HOME"/
USER user
WORKDIR "$USER_HOME"
RUN mkdir "$DATA_DIR"
VOLUME "$DATA_DIR"
RUN git clone --depth 1 https://github.com/Electron-Cash/Electron-Cash
WORKDIR Electron-Cash
RUN pip3 install -r contrib/requirements/requirements.txt --user
RUN pip3 install cherrypy peewee ec-slp-lib
RUN cat <<-EOF > "$USER_HOME"/expect_script.exp
set timeout -1
spawn ./electron-cash --dir "$DATA_DIR" --testnet create
match_max 100000
expect -exact "Password (hit return if you do not wish to encrypt your wallet):"
send -- "\r"
expect eof
EOF
RUN expect "$USER_HOME"/expect_script.exp
WORKDIR "$USER_HOME"
RUN git clone --depth 1 --branch docker_support https://gitlab.com/uak/light-crypto-faucet/ && \
cd "$USER_HOME"/light-crypto-faucet/faucet_web/ && \
cp tbch_web.config.sample $DATA_DIR/tbch_web.config && \
cp cherrypy.config.sample $DATA_DIR/cherrypy.config
CMD /usr/bin/python3 "$EC_DIR"/electron-cash --testnet --dir "$DATA_DIR" setconfig rpcport $rpc_port && \
/usr/bin/python3 "$EC_DIR"/electron-cash daemon --testnet start --dir "$DATA_DIR" && \
sleep 1 && \
export rpc_user=$("$EC_DIR"/electron-cash --testnet --dir "$DATA_DIR" getconfig rpcuser) && \
export rpc_password=$("$EC_DIR"/electron-cash --testnet --dir "$DATA_DIR" getconfig rpcpassword) && \
/usr/bin/python3 "$EC_DIR"/electron-cash daemon --testnet load_wallet --wallet $DATA_DIR/testnet/wallets/default_wallet --dir "$DATA_DIR" && \
echo "Send Funds to the following address:" &&\
/usr/bin/python3 "$EC_DIR"/electron-cash getunusedaddress --testnet --dir "$DATA_DIR" && \
cd "$USER_HOME"/light-crypto-faucet/faucet_web/ && \
/usr/bin/python3 "$USER_HOME"/light-crypto-faucet/faucet_web/web_faucet.py
Run the Container
To run the container get the Dockerfile
on server and run the following commands
sudo DOCKER_BUILDKIT=1 docker build --progress=plain . --tag=faucet01
sudo docker volume create faucet_volume
sudo docker run -v faucet_volume:/home/user/data -p 3000:8080 faucet01
It will build the container, create a volume to store data and keep it after restarts and lastly will run the container taking what is provided on port 8080
and serving it to port 3000
It's my first Docker file, I would appreciate community testing, expert reviews and comments.
Want to host your own?
drop a message at BCH builders Telegram channel, few people could donate tBCH coins to help you get your faucet running.
Thank you.
ClearSky