Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build bitcoinj Development Environment

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to build a bitcoinj development environment. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Bitcoinj development kit is a Java version of the bitcoin protocol implementation, you can use bitcoinj to achieve wallet management and transaction sending and receiving, without the local installation of bitcoin core software, this article will introduce the construction of bitcoinj development environment.

Install JDK

Install the latest version of JDK first, using openjdk or oracle's jdk.

Bitcoinj's core module supports java 7, but other modules require java 8, so we installed the latest JDK. Install openjdk directly apt under ubuntu:

~ $sudo apt-get update ~ $sudo apt-get install openjdk-8-jdk

After installation, execute the java command test:

~ $java-versionopenjdk version "1.8.0mm 131" install gradle

Bitcoinj uses gradle as its project build tool and requires version 3.4 +.

Download the latest version of the precompiled package from the gradle official website, then decompress and configure the environment variables:

~ $wget https://gradle.org/next-steps/?version=5.1&format=bin~$ mkdir / opt/gradle~$ unzip-d / opt/gradle gradle-5.1-bin.zip~$ echo PATH=/opt/gradle/bin:$PATH > > .bashrc ~ $source .bashrc source code construction

If you need to build bitcoinj from source code, you can download the code from github and then use gradle to perform the build process:

~ $git clone https://github.com/bitcoinj/bitcoinj.git~$ cd bitcoinj~/bitcoinj$ gradle clean build

The build output is in the build directory.

Develop the first bitcoinj application

Create a new project directory demo, as well as a Java source file and a gradle configuration file:

~ $mkdir demo~$ touch demo/App.java~$ touch demo/build.gradle

Write the following code in App.java to generate a random private key:

Package com.hubwiz.demo;import org.bitcoinj.core.ECKey;public class App {public static void main (String [] args) throws Exception {ECKey key = new ECKey (); String prv = key.getPrivateKeyAsHex (); System.out.format ("private = >% s\ n", prv);}}

Set the dependency on bitcoinj in the build.gradle configuration file:

Dependencies {compile 'org.bitcoinj:bitcoinj-core:0.14.7'}

Then run the demo project using gradle:

~ / demo$ gradle run

If you see the private key generated by the output of the terminal, then the bitcoinj development environment is deployed!

After reading the above, do you have any further understanding of how to build a bitcoinj development environment? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report