Skip to content

Instantly share code, notes, and snippets.

@lontivero
Last active April 8, 2022 10:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lontivero/dadb4cc8a7ad649bb9c9d1ede9e59d4d to your computer and use it in GitHub Desktop.
Save lontivero/dadb4cc8a7ad649bb9c9d1ede9e59d4d to your computer and use it in GitHub Desktop.
Wasabi CLI

Wasabi CLI

A tiny bash script to effortless interaction with Wasabi RPC Server.

$ ./wcli.sh listkeys | head -10 

fullkeypath       internal  keystate  label  p2wpkhscript                              pubkey                                                              pubkeyhash
84'/0'/0'/1/0     true      2         0      b0ba6bb14314bacd1f908eb2b9ecc74e0b041717  039d67f2c7c3dd1ed0ac301e677fe3abf6f059067796553211d562f46f2e420043  b0ba6bb14314bacd1f908eb2b9ecc74e0b041717
84'/0'/0'/1/1     true      2         0      6b470de643697581b2717e6d2b878470a26d5e83  02efaf8fddc729e51826439ebac6e5782f60890262fd6c0702f537062bc4fe00f2  6b470de643697581b2717e6d2b878470a26d5e83
84'/0'/0'/1/2     true      2         0      6e16974cb396a40fed7a0beaa561dcc411056843  0230a07c357acc2d1ff18f7d9efbd4d33fb18e5d57d65402a6a454e5afe7c03078  6e16974cb396a40fed7a0beaa561dcc411056843
84'/0'/0'/1/3     true      2         0      af3a7f07b296d3523f0d6860c6ca232bbcb8c87f  02b6aca09cb632ac208dd2396a74dc20a67b955faf6688211a08584bc291470018  af3a7f07b296d3523f0d6860c6ca232bbcb8c87f
84'/0'/0'/1/4     true      2         0      469d19d3db1967ffc54e9f73f66568d5370e7fd3  032c92e3dd33a79795fbc494ee49212a12e0e052d7342921288b9d2be9ea5c06bf  469d19d3db1967ffc54e9f73f66568d5370e7fd3
84'/0'/0'/1/5     true      2         0      7af90019e6da4786fe9303520a048133b4fad80f  03dc1e8714253cea85a7b24e6a43e03f1dc2547aa502e21841885ee79433bdbcba  7af90019e6da4786fe9303520a048133b4fad80f
84'/0'/0'/1/6     true      2         0      be9ef95bc97a4d576125230fecfef81c65a11a70  039e993093416851e1fda2c16324af20e5edfe1e265329035b64b7bee726882367  be9ef95bc97a4d576125230fecfef81c65a11a70
84'/0'/0'/1/7     true      2         0      edcc04910c022d265aa5169fccf14c5268797864  032678db6377b59372787da083afb1bfe2fefd50c26161dc058f7099e53e1a9fda  edcc04910c022d265aa5169fccf14c5268797864
$ ./wcli.sh gethistory | head -10 
datetime                   height   amount     tx                                                                islikelycoinjoin
2018-07-26T05:25:59+00:00  1355500  50000      6144f487705096397a39d2f0e7e23dd3e9c13d71e9cfc74b04e633eaf2f32a7a  false
2018-07-26T05:25:59+00:00  1355500  -555       ce41d4a5fe0c0da955210bf8722e43af8f580f87a005d7429272bfeb376426ea  false
2018-07-26T05:25:59+00:00  1355500  -720       5429cf93723f37af21f3c4ff5bb11e04af6e79a31aedcd4bbe93e9ae88989e1b  false
2018-07-26T05:25:59+00:00  1355500  -890       405822d6e574019c9f286b0f548d3824a3e305031556fa62a537b13745a0b0a0  false
2018-08-02T17:33:52+00:00  1356647  -17835     a98cca3e7e920bc97b85c17eb256bcaeabf7dec84491a8dfda8850ec4ec9bebf  false
2018-08-02T17:33:52+00:00  1356647  -13764     146eec8341caa0ad7bc63d325e3257e8e88fe4042df25bb9bf25e387909ebe8d  false
2018-08-02T17:52:24+00:00  1356649  219540     07d6708563d3ab4dba975a3058ec6d907bf6c52a1b2061b694548b77bf359dfd  false
2018-08-02T17:52:24+00:00  1356649  -13764     b84e225062daeee4064dd7d13396da0b26bbe644d74b9960f9094aa5424f1a32  false
2018-08-02T18:01:30+00:00  1356650  -13764     50386ba086db13ec1ca93fa8e1a364c2ed87f551b2f026c8e91c1c0a1b5221b9  false
$ ./wcli.sh getnewaddress "Ricardo"                                                                           9 changed files  Fixes/HwiProcessBridge 
{
  "address": "tb1q4glx2d8j9l86ltsxf9smdnkkdef8ut835zzvzg",
  "keyPath": "84'/0'/0'/0/100",
  "label": [
    "Ricardo"
  ],
  "publicKey": "032de9254c8ea96cb6d83e680336ed3abb9b3095b69635c422106d9e5d4df07d72",
  "p2wpkh": "0014aa3e6534f22fcfafae064961b6ced66e527e2cf1"
}
#!/usr/bin/env bash
function config_extract() {
echo $(cat ~/.walletwasabi/client/Config.json | jq -r "$1")
}
ENABLED="$(config_extract '.JsonRpcServerEnabled')"
CREDENTIALS=$(config_extract '.JsonRpcUser + ":" + .JsonRpcPassword')
ENDPOINT=$(config_extract '.JsonRpcServerPrefixes[0]')
if [[ "$ENABLED" == "false" ]]; then
echo "RPC server is disabled. Make sure to enable it by setting \"JsonRpcEnabled\":\"true\" in the Config.json file."
quit
fi
if [[ "$CREDENTIALS" == ":" ]]; then
BASIC_AUTH=""
else
BASIC_AUTH="--user ${CREDENTIALS}"
fi
METHOD=$1
shift
if [ $# -ge 1 ]; then
if [[ "$1" ]]; then
PARAMS="\"$1\""
shift
else
PARAMS="\"\""
shift
fi
while (( "$#" )); do
if [[ "$1" ]]; then
PARAMS="$PARAMS, $1"
else
PARAMS='$PARAMS, ""'
fi
shift
done
fi
REQUEST="{\"jsonrpc\":\"2.0\", \"id\":\"curltext\", \"method\":\"$METHOD\", \"params\":[$PARAMS]}"
RESULT=$(curl -s $BASIC_AUTH --data-binary "$REQUEST" -H "content-type: text/plain;" $ENDPOINT)
RESULT_ERROR=$(echo $RESULT | jq -r .error)
rawprint=(help)
if [[ "$RESULT_ERROR" == "null" ]]; then
if [[ " ${rawprint[@]} " =~ " ${METHOD} " ]]; then
echo $RESULT | jq -r .result
else
IS_ARRAY=$(echo $RESULT | jq -r '.result | if type=="array" then "true" else "false" end')
if [[ "$IS_ARRAY" == "true" ]]; then
echo entro
echo $RESULT | jq -r '.result | [.[]| with_entries( .key |= ascii_downcase ) ]
| (.[0] |keys_unsorted | @tsv)
, (.[]|.|map(.) |@tsv)' | column -t
else
echo $RESULT | jq .result
fi
fi
else
echo $RESULT_ERROR | jq -r .message
fi
@Kukks
Copy link

Kukks commented Jun 20, 2020

awesome, will fit in will with the btcpay stack soon :)

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