I have followed the instructions here to build my own bitcoin transaction.
Redeeming a raw transaction step by step example required
Currently my code can create a transaction and compute the SHA hash but I am struggling to sign it using ECDSA.
I have written so code to do it using bitcoinj but it is not working. I need some help signing a transaction using a java library or an API.
Here is what I have so far. Any help you be super appreciated :).
import org.apache.commons.codec.binary.Hex;
import org.bitcoinj.core.*;
import org.bitcoinj.core.ECKey.*;
public class Test3 {
public static void main(String[] args) {
//Given private key and SHA 256 Hash, sign a transaction
String shaHash = "15953935a135031bfec37d36a9d662aea43e1deb0ea463d6932ac6e537cb3e81";
String privateKey = "private key for the address";
byte[] priv = Base58.decode(privateKey);
// Generate ecsda key
ECKey ecdsa = ECKey.fromPrivate(priv);
Sha256Hash hash = new Sha256Hash(shaHash);
// Sign the transaction
ECDSASignature sig = ecdsa.sign(hash);
byte[] res = sig.encodeToDER();
String res2 = Hex.encodeHexString(res);
System.out.println(res2);
}
}