bit
bit copied to clipboard
Sweeping funds from multiple addresses to a single address
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.
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 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)
The program displays an error message. The library from bit.transaction import create_sweep_transaction doesn't exist
@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
@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.
Any update on sweep transactions with multiple keys? Is it going to be merged? This is a really useful feature!