Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: Lacrim on April 04, 2022, 01:21:11 PM



Title: Initiate a transaction from a PK
Post by: Lacrim on April 04, 2022, 01:21:11 PM
Hi. Is there any library or even third party API that allows to initiate a transaction and send funds just by using private keys? I want a lightweight solution that doesn't require running a full node or downloading the blockchain.


Title: Re: Initiate a transaction from a PK
Post by: jackg on April 04, 2022, 01:25:46 PM
If you value security, I'd suggest downloading a wallet like electrum (from electrum.org). The initial sync of a new wallet can take a few minutes and a few MB but it's a lot faster than bitcoin core.

There are websites too that can be used for signing transactions with private keys but you'd need good browser security and a good understanding of bitcoin to use them, like coinb.in


Title: Re: Initiate a transaction from a PK
Post by: NeuroticFish on April 04, 2022, 01:32:24 PM
Hi. Is there any library or even third party API that allows to initiate a transaction and send funds just by using private keys? I want a lightweight solution that doesn't require running a full node or downloading the blockchain.

I've seen today a topic about an open source web wallet that doesn't need local blockchain: https://bitcointalk.org/index.php?topic=5392903.0
It does calls to various servers and block explorers to do the job, so privacy is zero.

It's a HD wallet, so it works based on a seed, not PK. But it's open source; I don't know, it may be close enough to what you need, and if not, at least it can be a source of inspiration.


Title: Re: Initiate a transaction from a PK
Post by: stanner.austin on April 04, 2022, 01:47:38 PM
Very simple with python
example code.

Code:
#!python3

from bit import Key
from bit.format import bytes_to_wif

#for compressed private key address.
compressedkey = Key.from_hex("hex key data") # or from int compressedkey = Key.from_int(intdata)
compressedkey.create_transaction([], leftover='addressofyourchoicetorecieveall')

#for uncompressed private key address.
uncompressedkey = Key(bytes_to_wif(bytes.fromhex("hexdata"),compressed=False)) # or from int uncompressedkey = Key(bytes_to_wif(Key.from_int(intdata),compressed=False))
uncompressedkey.create_transaction([], leftover='addressofyourchoicetorecieveall')

More details at https://ofek.dev/bit/


Title: Re: Initiate a transaction from a PK
Post by: LoyceV on April 04, 2022, 02:40:07 PM
If you value security, I'd suggest downloading a wallet like electrum (from electrum.org).
To avoid exposing your private key to an online computer, this is much safer:
I was considering Electrum, only downside is that when creating a wallet, seed creation is exposed
Online:
Install Electrum on your PC.
Import your address to create a watch-only wallet.
Preview the transaction, Copy the unsigned transaction. Put it on a USB stick.

Offline and running without hard drive storage:
Get a Linux LIVE DVD. Use Knoppix or Tails (https://tails.boum.org/) for instance, or any other distribution that comes with Electrum pre-installed.
Unplug your internet cable. Close the curtains. Reboot your computer and start up from that DVD. Don't enter any wireless connection password. Keep it offline.
Start Electrum. Import your private key.
Copy your unsigned transaction from the USB stick, load it into Electrum.
CHECK the transaction in Electrum. Check the fees, check the amount, check all destination addresses (character by character (https://bitcointalk.org/index.php?topic=5190776.0)).
If all is okay, sign the transaction. Copy it back to your USB stick.
Turn off the computer. That wipes the Live LINUX from memory and all traces are gone.

Online:
Use your normal online Electrum to (check again and) broadcast the transaction.

Bonus:
After moving all your Bitcoin, and once the transaction confirmed, check if you own Forkcoins (https://bitcointalk.org/index.php?topic=2836875.msg56016704#msg56016704).


Title: Re: Initiate a transaction from a PK
Post by: ABCbits on April 05, 2022, 11:34:19 AM
OP, do you mind sharing why exactly you need create to create a transaction from PK using library/3rd party API? It sounds like XY problem and we could suggest better solution if you tell what's your goal.

If you value security, I'd suggest downloading a wallet like electrum (from electrum.org). The initial sync of a new wallet can take a few minutes and a few MB but it's a lot faster than bitcoin core.

Electrum also support CLI[1] if OP use-case involve server which doesn't have GUI. The documentation doesn't mention all command though, so you need to run electrum help or check the source code[2]

[1] https://electrum.readthedocs.io/en/latest/cmdline.html (https://electrum.readthedocs.io/en/latest/cmdline.html)
[2] https://github.com/spesmilo/electrum/blob/master/electrum/commands.py (https://github.com/spesmilo/electrum/blob/master/electrum/commands.py)