Bitcoin Forum
September 19, 2019, 09:20:48 AM *
News: Latest Bitcoin Core release: 0.18.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: bash script to automate proccess of sending BTC to other addresses  (Read 67 times)
darkv0rt3x
Jr. Member
*
Offline Offline

Activity: 38
Merit: 10


View Profile
August 29, 2019, 09:49:34 PM
Merited by LoyceV (2)
 #1

Hello guys.

I'm trying to automate the process of sending BTC to a couple of addresses with a bash script.

The addresses are in a file and I load each address into an array. This part is done.

How can I build/construct the bitcoin-cli sendmany command knowing that the number of addresses in this file may change? I mean, today I can have 3 addresses in that file, tomorrow I can have 5, the day after I can have only one address and so on.

Or what other approach can I try?
1568884848
Hero Member
*
Offline Offline

Posts: 1568884848

View Profile Personal Message (Offline)

Ignore
1568884848
Reply with quote  #2

1568884848
Report to moderator
PLAY NOW
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1568884848
Hero Member
*
Offline Offline

Posts: 1568884848

View Profile Personal Message (Offline)

Ignore
1568884848
Reply with quote  #2

1568884848
Report to moderator
DaveF
Hero Member
*****
Offline Offline

Activity: 1466
Merit: 770



View Profile WWW
August 30, 2019, 02:09:44 AM
Merited by LoyceV (2)
 #2

It's a bit of a cheat, BUT if you can format the text file the way bitcoin-cli wants it and start it with the bitcoin-cli command all you have to do then is run the file.

bitcoin-cli sendmany "" "{\"12345678ZZStgN5qWduEHyGrsSw72WEiTZ\":0.01,\"12345678ZZStgN5qWduEHyGrsSw72WEiTZ\":0.02}"

The other option is to send them as individual transactions:

bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.001
bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.002
bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.003

It's a bit easier as you are not needing the \ and { and everything else.
just start each line with bitcoin-cli sendtoaddress  and add the address and the amount and run it.

-Dave




.




  ▄▄▄▄▄▄▄▄▄▄▄▄▄
▄████████▀▀▀▀███▄
███████▀     ████
███████   ███████
█████        ████
███████   ███████
▀██████   ██████▀
  ▀▀▀▀▀   ▀▀▀▀▀

  ▄▄▄▄▄▄▄▄▄▄▄▄▄
▄██▀▀▀▀▀▀▀▀▀▀▀██▄
██    ▄▄▄▄▄ ▀  ██
██   █▀   ▀█   ██
██   █▄   ▄█   ██
██    ▀▀▀▀▀    ██
▀██▄▄▄▄▄▄▄▄▄▄▄██▀
  ▀▀▀▀▀▀▀▀▀▀▀▀▀

            ▄▄▄
█▄▄      ████████▄
 █████▄▄████████▌
▀██████████████▌
  █████████████
  ▀██████████▀
   ▄▄██████▀
    ▀▀▀▀▀

    ██  ██
  ███████████▄
    ██      ▀█
    ██▄▄▄▄▄▄█▀
    ██▀▀▀▀▀▀█▄
    ██      ▄█
  ███████████▀
    ██  ██




               ▄
       ▄  ▄█▄ ▀█▀      ▄
      ▀█▀  ▀   ▄  ▄█▄ ▀█▀
███▄▄▄        ▀█▀  ▀     ▄▄▄███       ▐█▄    ▄█▌   ▐█▌   █▄    ▐█▌   ████████   █████▄     ██    ▄█████▄▄   ▐█████▌
████████▄▄           ▄▄████████       ▐███▄▄███▌   ▐█▌   ███▄  ▐█▌      ██      █▌  ▀██    ██   ▄██▀   ▀▀   ▐█
███████████▄       ▄███████████       ▐█▌▀██▀▐█▌   ▐█▌   ██▀██▄▐█▌      ██      █▌   ▐█▌   ██   ██          ▐█████▌
 ████████████     ████████████        ▐█▌    ▐█▌   ▐█▌   ██  ▀███▌      ██      █▌  ▄██    ██   ▀██▄   ▄▄   ▐█
  ████████████   ████████████         ▐█▌    ▐█▌   ▐█▌   ██    ▀█▌      ██      █████▀     ██    ▀█████▀▀   ▐█████▌
   ▀███████████ ███████████▀
     ▀███████████████████▀
        ▀▀▀█████████▀▀▀
FIND OUT MORE AT MINTDICE.COM
darkv0rt3x
Jr. Member
*
Offline Offline

Activity: 38
Merit: 10


View Profile
September 01, 2019, 12:31:36 PM
 #3

It's a bit of a cheat, BUT if you can format the text file the way bitcoin-cli wants it and start it with the bitcoin-cli command all you have to do then is run the file.

bitcoin-cli sendmany "" "{\"12345678ZZStgN5qWduEHyGrsSw72WEiTZ\":0.01,\"12345678ZZStgN5qWduEHyGrsSw72WEiTZ\":0.02}"

The other option is to send them as individual transactions:

bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.001
bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.002
bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.003

It's a bit easier as you are not needing the \ and { and everything else.
just start each line with bitcoin-cli sendtoaddress  and add the address and the amount and run it.

-Dave


I'm taking another approach but your's is also an option as I might need to add different amounts to each address and also the change address!
But I'm already half way done to the first version. Then, to change to other format will be easier!

To send individual transactions will make more fees and if I can o it with a single transaction, fees will be less, right? The idea is also to be able to set several outputs into a single transaction to save in fees!
DaveF
Hero Member
*****
Offline Offline

Activity: 1466
Merit: 770



View Profile WWW
September 01, 2019, 01:16:21 PM
 #4

It's a bit of a cheat, BUT if you can format the text file the way bitcoin-cli wants it and start it with the bitcoin-cli command all you have to do then is run the file.

bitcoin-cli sendmany "" "{\"12345678ZZStgN5qWduEHyGrsSw72WEiTZ\":0.01,\"12345678ZZStgN5qWduEHyGrsSw72WEiTZ\":0.02}"

The other option is to send them as individual transactions:

bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.001
bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.002
bitcoin-cli sendtoaddress "12345678ZZStgN5qWduEHyGrsSw72WEiT" 0.003

It's a bit easier as you are not needing the \ and { and everything else.
just start each line with bitcoin-cli sendtoaddress  and add the address and the amount and run it.

-Dave


I'm taking another approach but your's is also an option as I might need to add different amounts to each address and also the change address!
But I'm already half way done to the first version. Then, to change to other format will be easier!

To send individual transactions will make more fees and if I can o it with a single transaction, fees will be less, right? The idea is also to be able to set several outputs into a single transaction to save in fees!

Fees are based on the size of the transaction (data size not BTC) which is usually based on the number of inputs, but many individual ones will most likely be more expensive to send.

I have used the method quoted above to do things for myself just because it is human readable.
I did all the processing in a DB, then dumped what I needed to text and ran a bitcoin-cli command against it.

It was a bit more programming work on my part, but I could look at a text file to see what happened instead of going through SQL logs trying to figure out what happened.
As you start to do more things the text file approach does become more labor YMMV.

And the obligatory, test it against testnet coins 1st or some alt-coin that costs almost nothing. So long as it's based off one of the newer core releases it should be fine. But if you mess something up your didn't loose real money.

-Dave




.




  ▄▄▄▄▄▄▄▄▄▄▄▄▄
▄████████▀▀▀▀███▄
███████▀     ████
███████   ███████
█████        ████
███████   ███████
▀██████   ██████▀
  ▀▀▀▀▀   ▀▀▀▀▀

  ▄▄▄▄▄▄▄▄▄▄▄▄▄
▄██▀▀▀▀▀▀▀▀▀▀▀██▄
██    ▄▄▄▄▄ ▀  ██
██   █▀   ▀█   ██
██   █▄   ▄█   ██
██    ▀▀▀▀▀    ██
▀██▄▄▄▄▄▄▄▄▄▄▄██▀
  ▀▀▀▀▀▀▀▀▀▀▀▀▀

            ▄▄▄
█▄▄      ████████▄
 █████▄▄████████▌
▀██████████████▌
  █████████████
  ▀██████████▀
   ▄▄██████▀
    ▀▀▀▀▀

    ██  ██
  ███████████▄
    ██      ▀█
    ██▄▄▄▄▄▄█▀
    ██▀▀▀▀▀▀█▄
    ██      ▄█
  ███████████▀
    ██  ██




               ▄
       ▄  ▄█▄ ▀█▀      ▄
      ▀█▀  ▀   ▄  ▄█▄ ▀█▀
███▄▄▄        ▀█▀  ▀     ▄▄▄███       ▐█▄    ▄█▌   ▐█▌   █▄    ▐█▌   ████████   █████▄     ██    ▄█████▄▄   ▐█████▌
████████▄▄           ▄▄████████       ▐███▄▄███▌   ▐█▌   ███▄  ▐█▌      ██      █▌  ▀██    ██   ▄██▀   ▀▀   ▐█
███████████▄       ▄███████████       ▐█▌▀██▀▐█▌   ▐█▌   ██▀██▄▐█▌      ██      █▌   ▐█▌   ██   ██          ▐█████▌
 ████████████     ████████████        ▐█▌    ▐█▌   ▐█▌   ██  ▀███▌      ██      █▌  ▄██    ██   ▀██▄   ▄▄   ▐█
  ████████████   ████████████         ▐█▌    ▐█▌   ▐█▌   ██    ▀█▌      ██      █████▀     ██    ▀█████▀▀   ▐█████▌
   ▀███████████ ███████████▀
     ▀███████████████████▀
        ▀▀▀█████████▀▀▀
FIND OUT MORE AT MINTDICE.COM
linenoise
Sr. Member
****
Offline Offline

Activity: 298
Merit: 270



View Profile
September 02, 2019, 04:41:39 AM
 #5

If everything is in an array you're almost there. Loop through the array to construct the sendmany variable, adding each address/value.

Each iteration add a comma to the end of the constructed variable, except for the last pair as it is not required.

Then perform the actual sendmany using the variable you have just created.




posmonero
Newbie
*
Offline Offline

Activity: 8
Merit: 2


View Profile
September 02, 2019, 04:57:00 AM
Merited by LoyceV (2)
 #6

addresses.txt:
Code:
<address1> <amount1>
<address2> <amount2>
...

send.sh:
Code:
#!/bin/bash

arg=''
while read line; do
    address=$(echo $line | cut -d' ' -f1)
    amount=$(echo $line | cut -d' ' -f2)
    if ! [ -z "$arg" ]; then arg="$arg,"; fi
    arg=$arg'"'$address'":'$amount
done <<< "$(cat addresses.txt)"

bitcoin-cli sendmany "" "{$arg}"

Runs:
Code:
bitcoin-cli sendmany "" '{"<address1>":<amount1>,"<address2>":<amount2>,"...":...}'
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!