Skip to content

Instantly share code, notes, and snippets.

@witoldsz
Last active July 6, 2019 18:04
Show Gist options
  • Save witoldsz/1109d6bec941a1824066a1b5afb79d9f to your computer and use it in GitHub Desktop.
Save witoldsz/1109d6bec941a1824066a1b5afb79d9f to your computer and use it in GitHub Desktop.
Semux: votes from SRC to DST. The amount is rounded to 1SEM and at least 2xFEE is left in wallet.
#!/bin/sh
USER=user
PASS=123456
SRC=0x6c9abb991956fe34e7e55ba024e3c6cd4a40eac4
DST=0x6c9abb991956fe34e7e55ba024e3c6cd4a40eac4
URL=http://${USER}:${PASS}@localhost:6171/v2.3.0
ONE_SEM=1000000000
FEE=5000000
CURL_="curl --silent -H 'accept: application/json'"
available=$($CURL_ -X GET "${URL}/account?address=${SRC}" | jq -r '.result.available')
amount=$(echo "($available - 2 * $FEE) / $ONE_SEM * $ONE_SEM" | bc)
echo "You have: $available"
echo "Vote amount: $amount"
$CURL_ -X POST "${URL}/transaction/vote?from=${SRC}&to=${DST}&value=${amount}"
echo
echo "Voted!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment