Giter Club home page Giter Club logo

java-client's Introduction

Due to the lack of usage, the Java SDK has been deprecated. However our RESTful APIs are extremely easy to integrate with any good HTTP client library.

java-client

Java SDK for BlockCypher

May requires the following dependencies to be added to your project:

  • org.glassfish.jersey.core -> jersey-client 2.9
  • javax.ws.rs -> javax.ws.rs-api 2.0.1
  • com.madgag -> sc-light-jdk15on 1.47.0.3

Transaction Example

  • Get an existing transaction with a given hash:
// Choose API version / currency / network / token, here v1 on Bitcoin's testnet network
BlockCypherContext context = new BlockCypherContext("v1", "btc", "test3", "YOURTOKEN");
String txHash = "09a228c6cf72989d81cbcd3a906dcb1d4b4a4c1d796537c34925feea1da2af35"
Transaction transaction = context.getTransactionService().getTransaction(txHash);
System.out.println("Transaction is confirmed? " + transaction.getConfirmed());
System.out.println("Transaction fees are:     " + transaction.getFees());

It will print the following:

Transaction is confirmed? 2014-08-03T15:52:11Z
Transaction fees are: 0
  • Create a transaction of 500000 satoshis from address mvYwMT3aZ5jNcRNNjv7ckxjbqMDtvQbAHz to address n3hDuRYeYaeV4aEBqYF9byMK5B2c3tR1nB
BlockCypherContext context = new BlockCypherContext("v1", "btc", "test3", "YOURTOKEN");
// WIF Format of your private Key
String myPrivateKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
IntermediaryTransaction unsignedTx = context.getTransactionService()
    .newTransaction(
        new ArrayList<String>(Arrays.asList("mvYwMT3aZ5jNcRNNjv7ckxjbqMDtvQbAHz")),
        new ArrayList<String>(Arrays.asList("n3hDuRYeYaeV4aEBqYF9byMK5B2c3tR1nB")),
        500000
    );
SignUtils.signWithBase58KeyWithPubKey(unsignedTx, myPrivateKey);

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

System.out.println("Sent transaction: " + GsonFactory.getGsonPrettyPrint().toJson(tx));

It will print the following:

Sent transaction: 
{
  "hash": "219e58e159851626b728a10d8f2aedcfca387dd4371242f421be27f70f19585a",
  "block_height": -1,
  "addresses": [
    "mvYwMT3aZ5jNcRNNjv7ckxjbqMDtvQbAHz",
    "n3hDuRYeYaeV4aEBqYF9byMK5B2c3tR1nB"
  ],
  "total": 89410000,
  "fees": 0,
  "relayed_by": "127.0.0.1:50987",
  "confirmed": "0001-01-01T00:00:00Z",
  "received": "2014-09-04T15:23:43.95376663Z",
  "ver": 1,
  "lock_time": 0,
  "vin_sz": 1,
  "vout_sz": 2,
  "confirmations": 0,
  "inputs": [
    {
      "prev_hash": "075f42cabe7eb01efd905d1ca0cb9fa23dd46db0658cd92c0198ef38814999f5",
      "output_index": 3,
      "script": "483045022100cca2901981d1c1840830b261963814eb1f14c56627e2a171b07a35ad44d49fbe0220485909ab2b79017861444840efce615e63a0d79fd1b69ef88c3ec00f1af255b5012102b93edbd6aa7df3510a1e76d355428f382e5a25e167560eea34055f6f98d6bae4",
      "output_value": 89410000,
      "addresses": [
        "mvYwMT3aZ5jNcRNNjv7ckxjbqMDtvQbAHz"
      ],
      "script_type": "pay-to-pubkey-hash"
    }
  ],
  "outputs": [
    {
      "value": 500000,
      "script": "76a914f343f510e12156df80fee18ea1a319002f55747788ac",
      "spent_by": "",
      "addresses": [
        "n3hDuRYeYaeV4aEBqYF9byMK5B2c3tR1nB"
      ],
      "script_type": "pay-to-pubkey-hash"
    },
    {
      "value": 88910000,
      "script": "76a914a4e9eecbbfd050cb2d47eb0452a97ccb607f53c788ac",
      "spent_by": "",
      "addresses": [
        "mvYwMT3aZ5jNcRNNjv7ckxjbqMDtvQbAHz"
      ],
      "script_type": "pay-to-pubkey-hash"
    }
  ]
}

NullData Example

  • Embed an OP_RETURN into the testnet blockchain and retrieve the resulting transaction hash:
BlockCypherContext context = new BlockCypherContext("v1", "btc", "test3", "YOURTOKEN");
NullData sentNullData = context.getTransactionService().sendNullData(new NullData("hello there", "string"));
System.out.println("Transaction hash of data embed:   " +  sentNullData.getHash());

java-client's People

Contributors

acityinohio avatar danielalexiuc avatar matthieu avatar sebay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

java-client's Issues

No license

Hi guys,
The repo is missing a license file. AFAIK if there is no license it's proprietary therefore nobody can use it without your explicit permission.

Maybe this is helpful: https://choosealicense.com/
Bitcoin Core (and many other Bitcoin projects) use MIT.

No (easy) way to page for paged results

Some results return paged results, such as TXIDs from a specific block.

There are no APIs to say "get me the next page of TXIDs" or "get me all of them". The next txids URL is exposed, but we have to dive into the RestUtils class to get at them.

junit tests fail

Multiple junit tests fail, both from the IDE and from "mvn clean install". For instance:

java.lang.ArrayIndexOutOfBoundsException: 0
at com.blockcypher.utils.sign.SignUtils.getBytesFromBase58Key(SignUtils.java:97)
at com.blockcypher.utils.sign.SignUtils.sign(SignUtils.java:50)
at com.blockcypher.utils.sign.SignUtils.signWithBase58KeyWithPubKey(SignUtils.java:40)
at com.blockcypher.service.TransactionServiceTest.testNewTransactionFromInputs(TransactionServiceTest.java:75)

and

java.lang.ArrayIndexOutOfBoundsException: 0
at com.blockcypher.utils.sign.SignUtils.getBytesFromBase58Key(SignUtils.java:97)
at com.blockcypher.utils.sign.SignUtils.sign(SignUtils.java:50)
at com.blockcypher.utils.sign.SignUtils.signWithBase58KeyWithPubKey(SignUtils.java:40)
at com.blockcypher.service.MultiSigTest.testMultiSigWithWebsocketOnConfirmedTransaction(MultiSigTest.java:57)

and

junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:55)
at junit.framework.Assert.assertTrue(Assert.java:22)
at junit.framework.Assert.assertNotNull(Assert.java:256)
at junit.framework.Assert.assertNotNull(Assert.java:248)
at com.blockcypher.service.AddressServiceTest.testGetAddress(AddressServiceTest.java:51)

no wallet api

Some of the cooler language clients support the /wallet api. This would be a significant improvement to the the java client. This would seem to require:

Ideally, we could also get some helper to generate the "extended public key" necessary for HD wallets.

ETH Transection issue

When we generate new address endpoint for ETH we will not receive "wif" key.
Then how will we make transaction with java-client as

// WIF Format of your private Key
String myPrivateKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

myPrivateKey must be in wif format.

is API rate limit based on token or token & ip?

Hi
I am currently writing an Android application that allow user to manage their digital currency wallet. It's possible that user could have multiple btc/eth wallet that need to query/update the latest balance when application is launched.

I am wondering is api rate limit based on token or ip? If it's based on token then all my users will use same token to query the wallet balance which will apparently reach the per second rate limit very quickly. If my App has more than 1000 users even the highest plan won't work in this case.

What should I do?

BlockCypherException raised when I try to sendTransaction

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?

Input class unusable

The input class from the transaction object is unusable. All fields are private and no accessors have been added.

This may be a problem for more classes than just Input.

misleading use of BigDecimal

Every field that represents a value in the "model" classes uses a BigDecimal. This is misleading because BlockCypher always sends and receives satoshis (which are whole numbers, not decimals).

Affected fields include:

Address.value
Transaction.fees
Transaction.total
Input.outputValue
Output.value
TransactionSummary.value

The TransactionService has two methods that take satoshi parameters as longs, and then wrap them in BigDecimal. This implies that longs are large enough to cover any value we may wish to represent. I'm not an expert on bitcoin/altcoin internals and do not know how many satoshis (or altcoin units) could theoretically exist, but if it's more than 9223372036854775807 (which is 92233720368 BTC) then BigInteger would be a safer bet. I'd probably lean towards playing it safe.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.