Skip to content

Instantly share code, notes, and snippets.

@torfbolt
Last active March 14, 2023 09:10
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save torfbolt/3dac87d5b21eabe6e8960d811e46c04a to your computer and use it in GitHub Desktop.
Script to generate a voluntary exit transaction for an eth2 validator key generated with launchpad
#!/bin/bash
# Usage: ./create-exit-transaction.sh /path/to/validator/keystore.json
BASEDIR=/tmp/ethdo-tmp
WN=import-wallet
ETHDO="ethdo"
# this doesn't work well so far
# docker pull wealdtech/ethdo
# ETHDO="docker run --network=host -v /tmp:/tmp -it wealdtech/ethdo"
$ETHDO version > /dev/null || { echo "Looks like ethdo is missing. Please install from https://github.com/wealdtech/ethdo/releases"; exit 1; }
$ETHDO chain info > /dev/null || { echo "ethdo has no connection to an Ethereum 2 node. Please make sure your Eth2 beacon node is reachable for RPC on localhost:4000"; exit 1; }
# the cleanup function will be the exit point
cleanup () {
# ignore stderr from rm incase the hook is called twice
rm -rf $BASEDIR &> /dev/null
exit $?
}
# register the cleanup function for all these signal types (see link below)
trap cleanup EXIT ERR INT TERM
$ETHDO wallet create --basedir $BASEDIR --wallet $WN
WUUID=$($ETHDO wallet info --basedir $BASEDIR --wallet $WN --verbose | grep UUID | cut -d" " -f2)
WDIR=$($ETHDO wallet info --basedir $BASEDIR --wallet $WN --verbose | grep Location | cut -d" " -f2)
echo "Created temporary wallet $WUUID in $WDIR"
KUUID=$(cat $1 | jq -r '.uuid')
KPUB=$(cat $1 | jq -r '.pubkey')
cat $1 | jq '. + {"name": "import-key"}' > $WDIR/$KUUID
echo "[{\"uuid\": \"$KUUID\", \"name\": \"import-key\"}]" > $WDIR/index
if [[ $($ETHDO wallet accounts --basedir $BASEDIR --wallet $WN) -eq "import-key" ]]; then
echo "Key 0x${KPUB:0:8} successfully imported"
else
echo "Importing key failed"
exit 1
fi
# Read Passphrase
echo -n "Please enter the passphrase for your key: "
read -s password
echo
EXITDATA=$($ETHDO validator exit --account import-wallet/import-key --basedir $BASEDIR --json-output --passphrase "$password")
[[ -z $EXITDATA ]] && echo "Failed to generate exit data" && exit 1
VAL_IDX=$(echo $EXITDATA | jq '.validator_index')
echo -n "Are you sure you want to send an exit transaction for validator #$VAL_IDX? This CAN NOT BE UNDONE. (Please enter upper case 'yes'): "
read confirm
[[ $confirm != "YES" ]] && exit
$ETHDO validator exit --account import-wallet/import-key --basedir $BASEDIR --passphrase "$password"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment