Skip to content

Instantly share code, notes, and snippets.

@diomark
Forked from polarker/sweepall.sh
Last active January 19, 2022 01:15
Show Gist options
  • Save diomark/727dc28a4d606e5b4c1143c0a07f2423 to your computer and use it in GitHub Desktop.
Save diomark/727dc28a4d606e5b4c1143c0a07f2423 to your computer and use it in GitHub Desktop.
Alephium sweep-all script
#!/bin/bash
Help()
{
echo "Add description of the script functions here."
echo
echo "Syntax: sweepall.sh [-w|p|a|u|i|h]"
echo "options:"
echo "w Wallet name."
echo "p API Key if set"
echo "a Address where we transfer the balance."
echo "u Unlock wallet first."
echo "i IP address for node if not localhost."
echo "h Print this Help."
echo
echo "Example: sweepall.sh -w testwallet -a ALPH_RECEIVE_ADDRESS [-u] [-p api_key] [-i node_ip]"
}
Unlock()
{
echo -n "Wallet password":
read -s password
if [ -z ${2} ]
then
curl -X POST http://${nodeAddress}:12973/wallets/${1}/unlock -H 'Content-Type: application/json' -d '{"password": "'${password}'"}'
else
curl -X POST http://${nodeAddress}:12973/wallets/${1}/unlock -H "X-API-KEY: ${2}" -H 'Content-Type: application/json' -d '{"password": "'${password}'"}'
fi
echo -e "\n"
}
while getopts w:up:i:a: flag
do
case "${flag}" in
w) wallet=${OPTARG};;
a) toaddress=${OPTARG};;
h) Help;;
p) apikey=${OPTARG};;
i) nodeAddress=${OPTARG};;
u) unlock=1;;
\?) Help;;
esac
done
if [ -z ${wallet} ]
then
Help
exit
fi
if [ -z ${toaddress} ]
then
Help
exit
fi
if [ -z ${nodeAddress} ]
then
nodeAddress="127.0.0.1"
fi
if [ ! -z ${unlock} ]
then
Unlock $wallet $apikey
fi
if [ -z ${apikey} ]
then
curl -X 'POST' \
"http://${nodeAddress}:12973/wallets/${wallet}/sweep-all-addresses" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"toAddress": "'${toaddress}'"}';
else
curl -X 'POST' \
"http://${nodeAddress}:12973/wallets/${wallet}/sweep-all-addresses" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "X-API-KEY: ${apikey}" \
-d '{"toAddress": "'${toaddress}'"}';
fi
@diomark
Copy link
Author

diomark commented Jan 19, 2022

Updated to use the new APIs for 1.2.x.. Also added APIKey or alternative nodename (-p and -i)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment