How to use bitpay and Java

I found this post about bitpay, but I don't know how to use it

https://help.bitpay.com/development/how-do-i-use-the-bitpay-java-client-library

I implemented this Code:

public void createInvoice() throws BitPayException
    {
        ECKey key = KeyUtils.createEcKey();
        BitPay bitpay = new BitPay(key);
        InvoiceBuyer buyer = new InvoiceBuyer();
        buyer.setName("Satoshi");
        buyer.setEmail("satoshi@bitpay.com");

        Invoice invoice = new Invoice(100.0,"USD");
        invoice.setBuyer(buyer);
        invoice.setFullNotifications(true);
        invoice.setNotificationEmail("satoshi@bitpay.com");
        invoice.setPosData("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");

        Invoice createInvoice = bitpay.createInvoice(invoice);
    }

How to implement the private key?

Solution

I believe this answer can be found in the following documents: https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/BitPay.java – that is, you will set the private key on the bitpay client instance There, you can find the appropriate constructor as needed You will use one or more of the following fields as needed:

private ECKey _ecKey = null;
private String _identity = "";
private String _clientName = "";
private Hashtable<String,String> _tokenCache;

Edit: the encryption and decryption of your private key exist here: https://github.com/bitpay/java-bitpay-client/blob/master/src/main/java/controller/KeyUtils.java

For example, if you use the following constructor:

public BitPay(URI privateKey) throws BitPayException,URISyntaxException,IOException {
    this(KeyUtils.loadEcKey(privateKey),BITPAY_PLUGIN_INFO,BITPAY_URL);
}

The URI that you will pass in your private key

The details are as follows: https://github.com/bitpay/java-bitpay-client/blob/master/GUIDE.md

Two very simple examples:

BitPay bitpay = new BitPay();
ECKey key = KeyUtils.createEcKey();
this.bitpay = new BitPay(key);

Second:

// Create the private key external to the SDK,store it in a file,and inject    the private key into the SDK.
String privateKey = KeyUtils.getKeyStringFromFile(privateKeyFile);
ECKey key = KeyUtils.createEcKeyFromHexString(privateKey);
this.bitpay = new BitPay(key);

After implementing the private key, you will need to initialize the client and connect to the server

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>