Tutorial: Send a transaction
Overview
This tutorial describes how to send a transaction to the Ember testnet using silvermint-tools
.
Prerequisites
- You are comfortable working from the command line
- You have a Debian install (bullseye+). See below if you need guidance for running in a Docker container.
- You have a stable internet connection
- URL for an Ember testnet validator - See About Ember
Install silvermint-tools
The silvermint-tools
package includes the wallet
executable, which generates keys, creates wallets, mints coins (if permitted), and sends and receives transactions.
To install silvermint-tools
deb package:
apt-get install -y ca-certificates
echo "deb [trusted=yes] https://apt.pyro.cloud stable main" | tee -a /etc/apt/sources.list.d/artifact-registry.list
apt-get update
apt-get install -y silvermint-tools
Script to create wallets, mint coins, and run transactions on Ember testnet
The following script results in:
- Creation of 2 wallets with keys
- Minting of coins to each wallet
- Balance checking
- Send of a transaction from one wallet to the other via the Ember testnet
- Final balance checking
#!/bin/bash
function WaitforFinalizedBalance {
AMOUNT=$1
echo "Waiting for amount: $AMOUNT"
export IFS=' '
while /bin/true; do
readarray -t OUTPUT <<< "$(wallet --apiserver $VALIDATOR_URL balance)"
regex='^[^ ]* ([0-9]+)'
if [[ $OUTPUT =~ $regex ]]; then
# extract the first group and print it
BALANCE="${BASH_REMATCH[1]}"
else
echo "Regex Error!"
exit
fi
if [ "$BALANCE" = "$AMOUNT" ]; then
break
else
sleep .5
fi
done
}
VALIDATOR_URL="$1"
DEST_WALLET="/tmp/wallet-b"
PAY_AMOUNT="100"
export VALIDATOR_URL DEST_WALLET PAY_AMOUNT
echo "Generating keys..."
wallet keygen
wallet keygen -o $DEST_WALLET
echo "Minting coins..."
wallet --apiserver $VALIDATOR_URL mint --amount=1000
wallet --apiserver $VALIDATOR_URL --wallet $DEST_WALLET mint --amount=1000
echo "Waiting for finalization... "
WaitforFinalizedBalance 1000
echo "Checking balances..."
wallet --apiserver $VALIDATOR_URL balance
wallet --apiserver $VALIDATOR_URL --wallet $DEST_WALLET balance
echo "Creating pay transaction..."
wallet --apiserver $VALIDATOR_URL pay -d=$(cat $DEST_WALLET.pub)/$PAY_AMOUNT
echo "Waiting for finalization... "
WaitforFinalizedBalance 900
echo "Checking balances..."
wallet --apiserver $VALIDATOR_URL balance
wallet --apiserver $VALIDATOR_URL --wallet $DEST_WALLET balance
Run silvermint-tools
in a Docker container
Dockerfile
FROM debian:latest
SHELL ["/bin/bash", "-c"]
RUN apt-get update
RUN apt-get install -y ca-certificates
RUN echo "deb [trusted=yes] https://apt.pyro.cloud stable main" | tee -a /etc/apt/sources.list.d/artifact-registry.list
RUN apt-get update
RUN apt-get install -y silvermint-tools
Docker Commands
docker build -t silvermint-tools .
docker run -it silvermint-tools bash
(... see script above...)
Get help
Ask questions in the Silvermint Discord community in the #silvermint-discussion channel.