Last active
March 14, 2023 09:10
Star
You must be signed in to star a gist
Script to generate a voluntary exit transaction for an eth2 validator key generated with launchpad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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