Skip to content

Instantly share code, notes, and snippets.

@davizalpe
Created January 29, 2017 22:38
Show Gist options
  • Save davizalpe/538a41a021394009cba169fe1d4c38be to your computer and use it in GitHub Desktop.
Save davizalpe/538a41a021394009cba169fe1d4c38be to your computer and use it in GitHub Desktop.
Bitcoin client scripts
#!/bin/bash
./$BITCOIN_HOME/bin/bitcoin-cli -regtest generate 101
#!/bin/bash
if [ $# -ne 1 ];
then
echo "usage: $0 account";
exit -1;
fi
bitcoin=$BITCOIN_HOME'/bitcoin-cli -regtest'
account=$1;
echo "List addresses from account:";
$bitcoin getaddressesbyaccount $account;
echo "";
echo "Received by address:";
$bitcoin listreceivedbyaddress 1 false true|grep $account -C 2
echo "Get unspent transactions"
addresses=`$bitcoin listreceivedbyaddress 1 false true|grep $account -C 1|grep address|cut -d' ' -f11|tr -d \",`;
#addresses=`echo $addresses | sed 's, *,,; s, *$,,'`
addressesjson=`echo $addresses | sed -r 's/ 2/","2/g'`
$bitcoin listunspent 1 99999 '''[
"'$addressesjson'"
]'''
#!/bin/bash
# Based in https://bitcoin.org/en/developer-examples#p2sh-multisig
bitcoin=$BITCOIN_HOME"/bin/bitcoin-cli"
echo "";
echo create 3 addresses
NEW_ADDRESS1=`$bitcoin getnewaddress`
echo $NEW_ADDRESS1
NEW_ADDRESS2=`$bitcoin getnewaddress`
echo $NEW_ADDRESS2
NEW_ADDRESS3=`$bitcoin getnewaddress`
echo $NEW_ADDRESS3
echo "";
echo validate address 1
$bitcoin validateaddress $NEW_ADDRESS1
echo "read public key 1"
read PUBLIC1
echo validate address 2
$bitcoin validateaddress $NEW_ADDRESS2
echo "read public key 2"
read PUBLIC2
echo validate address 3
$bitcoin validateaddress $NEW_ADDRESS3
echo "read public key 3"
read PUBLIC3
echo "";
echo create multisig
$bitcoin createmultisig 2 '''["'$PUBLIC1'", "'$PUBLIC2'", "'$PUBLIC3'"]'''
echo dump private keys
PRIV1=`$bitcoin dumpprivkey $NEW_ADDRESS1`
PRIV2=`$bitcoin dumpprivkey $NEW_ADDRESS2`
PRIV3=`$bitcoin dumpprivkey $NEW_ADDRESS3`
echo $PRIV1
echo $PRIV2
echo $PRIV3
#!/bin/bash
if [ $# -gt 0 ] && [ $1=="-regtest" ];
then
$BITCOIN_HOME/bin/bitcoin-cli -regtest help
echo "";
echo "Select a method: ";
read METHOD;
echo "\"$METHOD\""
curl --user ${BITCOIN_RPC_USER}:${BITCOIN_RPC_PASS} --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": $METHOD, "params": [] }' -H 'content-type: text/plain;' https://localhost:8332/
fi
curl --user ${BITCOIN_RPC_USER}:${BITCOIN_RPC_PASS} --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getaccountaddress", "params": ["user"] }' -H 'content-type: text/plain;' https://localhost:8332/
./$BITCOIN_HOME/bin/bitcoin-cli -regtest getaccountaddress 1
./$BITCOIN_HOME/bin/bitcoin-cli -regtest listtransactions
#!/bin/bash
bitcoin=$BITCOIN_HOME"/bin/bitcoin-cli -regtest"
$bitcoin sendtoaddress $1 $2
#!/bin/bash
./$BITCOIN_HOME/bin/bitcoind \
-regtest \
-txindex \
-daemon \
-paytxfee=0.00005000 \
-blocknotify="echo '%s' | nc localhost 4001" \
-walletnotify="echo '%s' | nc localhost 4002" \
-alertnotify="echo '%s' | nc localhost 4003"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment