Author

Topic: How to Create Bitcoin Transactions from a Server (Read 208 times)

hero member
Activity: 1680
Merit: 655
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.
sr. member
Activity: 443
Merit: 350
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)
copper member
Activity: 1652
Merit: 1901
Amazon Prime Member #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)".
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. 
legendary
Activity: 2114
Merit: 1293
There is trouble abrewing
{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.
jr. member
Activity: 43
Merit: 20
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.
jr. member
Activity: 43
Merit: 20
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?
legendary
Activity: 2114
Merit: 1293
There is trouble abrewing
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)".
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
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.
jr. member
Activity: 43
Merit: 20
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?
jr. member
Activity: 43
Merit: 20
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.
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
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
legendary
Activity: 3500
Merit: 6320
Crypto Swap Exchange
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
jr. member
Activity: 43
Merit: 20
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.
Jump to: