Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Sanka555 on January 27, 2022, 08:27:26 AM



Title: simple transaction bitcoin . Java
Post by: Sanka555 on January 27, 2022, 08:27:26 AM
java 8

I have 2 addresses. the key from the first and the amount to be sent.
I assume that the amount at the address is sufficient
I need the simplest possible code to send a given amount of Satoshi from one to another in testnet.
 Please tell me how to do it.
Thank you very much in advance  :)

example:

Quote
String myAdress= "tbc1qnsfqpgy3z8vnjpn68j7drhekwztrxtr9.....";
String myKey="KzerGrhf................XddJ";
String destination= "tbc1qnsfqpgy3z8vnjpn68j7drhekwztrxtr92.....";
.
.
.

public static void name(String myAdress, String myKey, String destination, long summ, long commission){
...
}



Title: Re: simple transaction bitcoin . Java
Post by: vjudeu on January 27, 2022, 09:43:56 AM
Quote
I need the simplest possible code to send a given amount of Satoshi from one to another in testnet.
Quote
bc1qnsfqpgy3z8vnjpn68j7drhekwztrxtr92p7893
This address is not for testnet, but for mainnet. In testnet, you would have tb1q address. Also, you have invalid address in "myAdress", because it ends with 5 instead of 3.


Title: Re: simple transaction bitcoin . Java
Post by: n0nce on January 27, 2022, 09:53:27 AM
public static void(String myAdress, String myKey, String destination, long summ, long commission){
...
}
Pretty sure this function is invalid, since it has no name. Or maybe it's interpreted as having the name 'void', but then you wouldn't have a return type.
It should look like this, where send is a name you can choose.

Code:
public static void send(String myAdress, String myKey, String destination, long summ, long commission){
...
}


Title: Re: simple transaction bitcoin . Java
Post by: odolvlobo on January 28, 2022, 03:25:52 AM
I hate to be the one to break the bad news. Your code is woefully inadequate.

If you are constructing the transaction yourself, then you need more information than just the "sending" address and its private key. Here is some information on constructing a transaction (sorry, its not the best source): https://stackoverflow.com/questions/60255876/signing-a-bitcoin-segwit-transaction

If you are using a wallet through an API, then you will need look into how to use the API.