pull down to refresh

You could do this with cron, python & electrum.
Do you know cron and python?
I know cron and electrum, but not Python.
reply
Ironically, your question was asked nearly identically on the Bitcoin Stack Exchange:
How to "Autoforward" incoming BTC using Electrum https://bitcoin.stackexchange.com/questions/114615
Unfortunately, nobody has shared a script there that is ready to go that does that.
I see this article, ... a how-to if you are running bitcoin core, which you could then create a script to do it:
There's also this article which may be of help, for someone writing a script. Different from above in that it uses some third party API service.
Send bitcoin from your wallet using JavaScript https://blog.logrocket.com/sending-bitcoin-with-javascript/
And finally, maybe some of these scripts will help you in some way.
Various shell scripts, mainly to be used together with Bitcoin Core (bitcoind or bitcoin-qt) wallet. https://github.com/kristapsk/bitcoin-scripts
reply
Just a caveat ... it's not that hard for a script to do something you didn't intend for it to do. Bitcoin transactions are non-reversible, as you likely know, ... so a script doing something dumb like forgetting to calculate the change amount properly would result in the change going to the miner.
So, ... use testnet if you are developing a script, and have a second set of eyes on a script before you run it live on bitcoin main.
reply
Well, you wouldn't have to learn very much python to do it. Might be half a dozen lines code to figure out.
A small bounty would probably get you 90% there. If somebody knew the electrum API, I'm sure it's like a half hour chore for them. But, could be 12h+ for a n00b.
Is the list of keys static? Or manually maintainable?
If I wasn't traveling this week, I could do it for you.
reply
The list is manually maintainable. That is the only thing that would need maintenance, besides OS upgrades. I could pay you via lightning for assistance whenever you are done traveling, no rush or pressure.
reply
I got something partially functional, kicking the tires on the API tonight. It's not as straightforward to use the electrum API as I thought.
Deploying & configuring could turn into a bigger challenge than I initially thought too.
100% possible. Not sure if I'll have enough time. I'll try to circle back on this 2 weeks from now.
reply
300 sats \ 1 reply \ @jeff 7 Aug 2022
@tech5, I got it to work on testnet. Here is a guide for you.

Pre-amble

The instructions are written to target testnet. You can get testnet bitcoins from a faucet on google. Remove --testnet from all commands after you have something functioning on your machine.
I tested it with 1, 2 and 3 funded addresses on testnet. Note that the fee is static. I'm sure it'll work with infinite addresses.

1 Setup Server

  1. Install your fav linux distro (I did this on Ubuntu).
  2. Install python 3, optionally in a virtual environment
  3. Install electrum
  4. Install jq (Eg. sudo apt-get install jq)
Hopefully the above is easy enough for you. There are plenty of guides online for these.
Depending on your build, you may need to run the following.
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
Electrum will give you errors if you need this.

2 Configure Electrum

2 B - Daemon

Use Electrum docs & CLI to configure the daemon.
This will involve at the very least, setting a static port. Choose ports that aren't in use. No need to expose these ports externally, unless you know what you're doing.
electrum setconfig rpcport 7776 --offline --testnet
And mainnet, change the port to 7777.

2 - B Use Electrum UI to Setup your Wallet

electrum --testnet
Follow the prompts to setup your wallet with a password. Import the private keys you have into the wallet using the UI. Shut down the UI.

3 Run the Daemon

electrum daemon -d --testnet

4 Configure your Environment

export FEE=0.00001 # in BTC export DEST_ADDRESS=tb1qun6lw4f6mdqy97q373gs75m00etdklyrjjs2h2 export PASSWORD=pass export WALLET=~/.electrum/testnet/wallets/default_wallet_testnet

5 Load the wallet

electrum load_wallet -w $WALLET -W $PASSWORD --testnet

6 Get Addresses with Balances, Sweep & Broadcast

Run the following. It will list the addresses with balances, pull out the private keys, format them ready for the sweep command, prepare and sign a transaction, then broadcast it.
electrum listaddresses --funded -w $WALLET --testnet | electrum getprivatekeys - -w $WALLET -W $PASSWORD --testnet | jq -c | sed 's/[^a-zA-Z0-9:]/ /g' | electrum sweep - $DEST_ADDRESS --testnet -f $FEE | electrum signtransaction - -w $WALLET -W $PASSWORD --testnet | electrum broadcast - --testnet

7 Schedule

Add the command in step 5 to a cron schedule. So long as the electrum daemon and the wallet is unlocked the command will work.

8 Reboot

Run the commands from 3, 4 and 5 on startup of the server. Alternatively, you can run them before each command, but you would need to shut down the daemon if you did that.
reply
Wow that’s awesome!! I will give it a try. Thank you for sharing!
reply