blockcypher / java-client

Java SDK for BlockCypher
Apache License 2.0
41 stars 56 forks source link

BlockCypherException raised when I try to sendTransaction #7

Closed TommyYehCool closed 4 years ago

TommyYehCool commented 7 years ago

When I try to execute the code as below:

IntermediaryTransaction unsignedTx 
  = context.getTransactionService().newTransaction(
           new ArrayList<String>(Arrays.asList(srcAddress)),
           new ArrayList<String>(Arrays.asList(destAddress)),
           satoshis);

SignUtils.signWithBase58KeyWithPubKey(unsignedTx, privateKey);

Transaction tx = context.getTransactionService().sendTransaction(unsignedTx);

I got the Exception

Exception in thread "main" BlockCypherException{message=Bad Request, status=400, blockCypherError=[Error{error='Error validating transaction: Error running script for input 0 referencing d91883459a7bb11c84da2d883ced509d9fc14a82065c194d53245211cb58c55e at 1: Script was NOT verified successfully.'}], exception=null}
    at com.blockcypher.utils.rest.jersey.JerseyRestUtils.getBlockCypherException(JerseyRestUtils.java:90)
    at com.blockcypher.utils.rest.jersey.JerseyRestUtils.post(JerseyRestUtils.java:33)
    at com.blockcypher.utils.rest.jersey.JerseyRestUtils.post(JerseyRestUtils.java:50)
    at com.blockcypher.utils.rest.RestUtils.post(RestUtils.java:20)
    at com.blockcypher.service.TransactionService.postTransaction(TransactionService.java:59)
    at com.blockcypher.service.TransactionService.sendTransaction(TransactionService.java:133)

Can someone remind me where the problem is?

cryptozion commented 6 years ago

any one alive? do you already abandon this sdk?

cryptozion commented 6 years ago

BlockCypherContext context = new BlockCypherContext("v1", "btc", "test3", "YOURTOKEN"); // WIF Format of your private Key String myPrivateKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; IntermediaryTransaction unsignedTx = context.getTransactionService() .newTransaction( new ArrayList(Arrays.asList("mvYwMT3aZ5jNcRNNjv7ckxjbqMDtvQbAHz")), new ArrayList(Arrays.asList("n3hDuRYeYaeV4aEBqYF9byMK5B2c3tR1nB")), 500000 ); SignUtils.signWithBase58KeyWithPubKey(unsignedTx, myPrivateKey);

I solved my problem, the private key must be the WIF format,I made a mistake.

DiamondLi commented 6 years ago

@shapowang Thanks for your answer. I solved this problem too as you said

quentinlesceller commented 4 years ago

Feel free to reopen if this is still relevant.