Author

Topic: bash script to automate proccess of sending BTC to other addresses (Read 171 times)

hero member
Activity: 1176
Merit: 647
I rather die on my feet than to live on my knees
Ohhh.. I even forgot this thread of mine.

Thank you for that example. It's exactly what I needed and with 1/5 of the code I did. Smiley
I completed this small task I had in the past but I might update it with this code, actually.
newbie
Activity: 8
Merit: 2
addresses.txt:
Code:
 

...

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 "" '{"":,"":,"...":...}'
sr. member
Activity: 300
Merit: 290
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.




legendary
Activity: 3458
Merit: 6231
Crypto Swap Exchange
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
hero member
Activity: 1176
Merit: 647
I rather die on my feet than to live on my knees
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!
legendary
Activity: 3458
Merit: 6231
Crypto Swap Exchange
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
hero member
Activity: 1176
Merit: 647
I rather die on my feet than to live on my knees
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?
Jump to: