Bitcoin Forum
November 14, 2024, 11:29:09 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to Create Bitcoin Transactions from a Server  (Read 208 times)
vicknick (OP)
Jr. Member
*
Offline Offline

Activity: 43
Merit: 20


View Profile
January 26, 2020, 02:35:53 PM
 #1

I am exploring ways to create a bitcoin transaction on a website server. When a user has typed in his bitcoin address and the amount to be sent, how do you create a bitcoin transaction to send the specified amount to his/her address on a server? I tried searching online but so far I can only find minimal info about this.

Some says you can install bitcoin core on the server, but the storage needed to hold the blockchain exceeds my capacity. Electrum seems to be a good option since it doesn't download the entire blockchain, but there is no info on how to make a transaction from the server code (I am writing in JavaScript).

Any recommendations are highly appreciated.
DaveF
Legendary
*
Offline Offline

Activity: 3654
Merit: 6671


Crypto Swap Exchange


View Profile WWW
January 26, 2020, 02:43:18 PM
 #2

I think you are just looking to create the raw transaction and send that?
If so:
https://en.bitcoin.it/wiki/Raw_Transactions

If you are looking to do something else you are going to have to define what you are looking to do a bit more.
Also, if the server you are working on can't hold the blockchain it's probably time to get a new one.

-Dave

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
ranochigo
Legendary
*
Offline Offline

Activity: 3038
Merit: 4420


Crypto Swap Exchange


View Profile
January 26, 2020, 02:43:24 PM
Merited by BrewMaster (1)
 #3

You don't have to keep the entire blockchain on your computer for the whole time. You can delete the older blocks as you go with pruning and keep it from exceeding a certain size.

That being said, Electrum offers JSONRPC and you can easily integrate that with your code. There's some examples here[1].


[1] https://electrum.readthedocs.io/en/latest/merchant.html

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
vicknick (OP)
Jr. Member
*
Offline Offline

Activity: 43
Merit: 20


View Profile
January 26, 2020, 02:48:52 PM
 #4

Quote
That being said, Electrum offers JSONRPC and you can easily integrate that with your code. There's some examples here[1].

That's accepting bitcoin, however what I want is to send bitcoin to users.
vicknick (OP)
Jr. Member
*
Offline Offline

Activity: 43
Merit: 20


View Profile
January 26, 2020, 02:58:04 PM
 #5

I think you are just looking to create the raw transaction and send that?
If so:
https://en.bitcoin.it/wiki/Raw_Transactions

If you are looking to do something else you are going to have to define what you are looking to do a bit more.
Also, if the server you are working on can't hold the blockchain it's probably time to get a new one.

-Dave

Does it require bitcoin core to be installed? Is there other ways to send bitcoin from server without installing bitcoin core wallet?
ranochigo
Legendary
*
Offline Offline

Activity: 3038
Merit: 4420


Crypto Swap Exchange


View Profile
January 26, 2020, 03:06:40 PM
 #6

Does it require bitcoin core to be installed? Is there other ways to send bitcoin from server without installing bitcoin core wallet?
Would pruning not work for you? It's possible for you to use a code to script your own raw transaction and then directly broadcast the raw transaction to the other nodes. But that would require you to be able to obtain the information about your UTXO in the first place and it would preferably be from your Bitcoin node.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
BrewMaster
Legendary
*
Offline Offline

Activity: 2128
Merit: 1293


There is trouble abrewing


View Profile
January 26, 2020, 03:34:10 PM
 #7

Quote
That being said, Electrum offers JSONRPC and you can easily integrate that with your code. There's some examples here[1].

That's accepting bitcoin, however what I want is to send bitcoin to users.

you can do both with Electrum JSONRPC. the commands support both creation and signing of transactions from your keys with commands such as "signtransaction()" and then you can broadcast them using "broadcast(tx)".

There is a FOMO brewing...
vicknick (OP)
Jr. Member
*
Offline Offline

Activity: 43
Merit: 20


View Profile
January 26, 2020, 04:00:45 PM
 #8

Would pruning not work for you? It's possible for you to use a code to script your own raw transaction and then directly broadcast the raw transaction to the other nodes. But that would require you to be able to obtain the information about your UTXO in the first place and it would preferably be from your Bitcoin node.
However when users deposit bitcoin to the website, each of them have different addresses, which are generated in deterministic manner. The reason I prefer to use a wallet is because when the server send bitcoin to external address given by the user, the wallet is able to send bitcoin by combining from different addresses. I think writing own script to implement this feature would be harder?
vicknick (OP)
Jr. Member
*
Offline Offline

Activity: 43
Merit: 20


View Profile
January 26, 2020, 04:15:10 PM
 #9

Quote
That being said, Electrum offers JSONRPC and you can easily integrate that with your code. There's some examples here[1].

That's accepting bitcoin, however what I want is to send bitcoin to users.

you can do both with Electrum JSONRPC. the commands support both creation and signing of transactions from your keys with commands such as "signtransaction()" and then you can broadcast them using "broadcast(tx)".
Is there any examples/documentations for this? Electrum's documentation doesn't seem to have the info.
BrewMaster
Legendary
*
Offline Offline

Activity: 2128
Merit: 1293


There is trouble abrewing


View Profile
January 26, 2020, 04:29:53 PM
 #10

{snip}
Is there any examples/documentations for this? Electrum's documentation doesn't seem to have the info.

there is the electrum docs here: https://electrum.readthedocs.io/en/latest/merchant.html that contain the needed information to start accepting bitcoin as a merchant using Electrum. it mainly explains accepting payment but the principle is the same for sending payments too.
there are also some articles on the internet that you can find in google search for keyword "bitcoin" + "electrum" + "merchants". i haven't used any of them so i can't recommend any.

There is a FOMO brewing...
PrimeNumber7
Copper Member
Legendary
*
Offline Offline

Activity: 1666
Merit: 1901

Amazon Prime Member #7


View Profile
January 27, 2020, 06:44:52 AM
 #11

Quote
That being said, Electrum offers JSONRPC and you can easily integrate that with your code. There's some examples here[1].

That's accepting bitcoin, however what I want is to send bitcoin to users.

you can do both with Electrum JSONRPC. the commands support both creation and signing of transactions from your keys with commands such as "signtransaction()" and then you can broadcast them using "broadcast(tx)".
Is there any examples/documentations for this? Electrum's documentation doesn't seem to have the info.
You would need to use a series of RPC commands, such as listunspent and signtransaction. You would also need to craft a transaction outside of electrum if you were automating sending transactions.

If you absolutely do not wish to use a full node, you can also use the blockchain.com wallet API. Blockchain.com/info does have a history of screwups that has resulted in the loss of customer money, but I believe this to be less common in recent years.

I do believe running a full node and using the sendtoaddress RPC command would probably be your best solution. The cost to run a fully validating full node is not extraordinary. 
MrFreeDragon
Sr. Member
****
Offline Offline

Activity: 443
Merit: 350


View Profile
January 29, 2020, 12:52:32 PM
 #12

Have a look at this service:

https://github.com/OutCast3k/coinbin/
https://coinb.in/

This tool helps to create transactions online and broadcast them. If you go to the source code on github, you can find the useful information for you and use it on your web server.

Actually there are 2 steps: (1) create raw transaction, (2) broadcast the transaction. Both steps are realized in the tool.

EDIT: The tool uses JavaScript (as you asked in the OP)

Theb
Hero Member
*****
Offline Offline

Activity: 1680
Merit: 655


View Profile
January 29, 2020, 07:55:50 PM
 #13

there is the electrum docs here: https://electrum.readthedocs.io/en/latest/merchant.html that contain the needed information to start accepting bitcoin as a merchant using Electrum. it mainly explains accepting payment but the principle is the same for sending payments too.
there are also some articles on the internet that you can find in google search for keyword "bitcoin" + "electrum" + "merchants". i haven't used any of them so i can't recommend any.

Like what the OP stated in his other post he would also like to send crypto payments automatically om his side. Electrum's merchant function in their document only accept payments as a business and doesn't have any documentation for them sending the payments. @OP on this part I think it will be harder to find a sample script on what you are asking since even e-commerce crypto payment processors like Bitpay and Coinbase commerce only has a function to receive payments for your business. You would need to consider the balance your wallet have, the fees you will be handling, and also the conversion of the prices in USD all of which if it will go wrong your funds will be instantly flushed.

..bustadice..         ▄▄████████████▄▄
     ▄▄████████▀▀▀▀████████▄▄
   ▄███████████    ███████████▄
  █████    ████▄▄▄▄████    █████
 ██████    ████████▀▀██    ██████
██████████████████   █████████████
█████████████████▌  ▐█████████████
███    ██████████   ███████    ███
███    ████████▀   ▐███████    ███
██████████████      ██████████████
██████████████      ██████████████
 ██████████████▄▄▄▄██████████████
  ▀████████████████████████████▀
                     ▄▄███████▄▄
                  ▄███████████████▄
   ███████████  ▄████▀▀       ▀▀████▄
               ████▀      ██     ▀████
 ███████████  ████        ██       ████
             ████         ██        ████
███████████  ████     ▄▄▄▄██        ████
             ████     ▀▀▀▀▀▀        ████
 ███████████  ████                 ████
               ████▄             ▄████
   ███████████  ▀████▄▄       ▄▄████▀
                  ▀███████████████▀
                     ▀▀███████▀▀
           ▄██▄
           ████
            ██
            ▀▀
 ▄██████████████████████▄
██████▀▀██████████▀▀██████
█████    ████████    █████
█████▄  ▄████████▄  ▄█████
██████████████████████████
██████████████████████████
    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
       ████████████
......Play......
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!