bit icon indicating copy to clipboard operation
bit copied to clipboard

Sweeping funds from multiple addresses to a single address

Open joemarct opened this issue 6 years ago • 6 comments

I needed to sweep funds from multiple addresses I own (i.e. I have their private keys) to a single address. I did not find a way to do that from the documentation so I added that functionality in my fork.

Here's a reference to my commit: https://github.com/joemarct/bit/commit/42450a5de7d4ee621863c5e804d903aa37a349fa

Usage is as follows:

from bit import PrivateKey
from bit.transaction import create_sweep_transaction
from bit.network import NetworkAPI

# Generate addresses (or import private keys)
key1 = PrivateKey()
key2 = PrivateKey()
key3 = PrivateKey()

# Sweep the funds of key1, key2 and key3 to the destination address below
destination = 'n1n2YUzwJSNueBsKE6D9kaQGrLFj3Wc3bL'
sweep_tx = create_sweep_transaction([key1, key2, key3], destination)

# Broadcast the transaction
NetworkAPI.broadcast_tx_testnet(sweep_tx)

If there is interest in having this merged here, I'll create a pull request.

joemarct avatar Feb 13 '18 10:02 joemarct

Hi. Is possible sweep with wif key?? Exemple: key1 = PrivateKey() wif = key1.to_wif() destination = 'n1n2YUzwJSNueBsKE6D9kaQGrLFj3Wc3bL' sweep_tx = create_sweep_transaction([wif], destination)

Broadcast the transaction

NetworkAPI.broadcast_tx_testnet(sweep_tx)

xcbtrader avatar May 19 '18 12:05 xcbtrader

@xcbtrader In your example, you could have passed key1 directly into the list, you shouldn't have extracted the wif from it. But anyway, if there are cases where you have the wif key, I would say you should just create the PrivateKey object out of the wif by doing:

from bit import wif_to_key
from bit.transaction import create_sweep_transaction

key1 = wif_to_key('your-wif-here')
destination = 'destination-address-here'
sweep_tx = create_sweep_transaction([key1], destination)

joemarct avatar May 20 '18 23:05 joemarct

The program displays an error message. The library from bit.transaction import create_sweep_transaction doesn't exist

xcbtrader avatar May 21 '18 04:05 xcbtrader

@xcbtrader The create_sweep_transaction has not been merged to master branch. This is what this discussion is all about. I will create a pull request if the maintainers of this repo think it would be useful to merge my changes. If you want to use it now, you can clone my fork and try that function from there. Here's the link to my fork of this repo: https://github.com/joemarct/bit

joemarct avatar May 21 '18 09:05 joemarct

@ofek should add this kinds of functionality. This will be useful & save time when you need to collect all the amount from thousands of addresses to a single address. Now i need to do it one by one using loop & it takes long time.

expired-brain avatar Apr 09 '19 18:04 expired-brain

Any update on sweep transactions with multiple keys? Is it going to be merged? This is a really useful feature!

timwoocker avatar Jan 16 '21 00:01 timwoocker