以太坊java庫(kù)EthereumJ簡(jiǎn)介

EthereumJ是以太坊協(xié)議的純Java實(shí)現(xiàn)。有關(guān)以太坊及其目標(biāo)的高級(jí)信息,請(qǐng)?jiān)L問(wèn)ethereum.org,其白皮書(shū)提供了一個(gè)完整的概念的概述,和黃皮書(shū)一起提供了協(xié)議的正式定義。

我們盡可能保持EthereumJ簡(jiǎn)單。對(duì)于JSON-RPC支持和其他客戶端功能,請(qǐng)看Ethereum Harmony。

運(yùn)行EthereumJ

作為依賴(lài)項(xiàng)添加到Maven項(xiàng)目:

   <dependency>
     <groupId>org.ethereum</groupId>
     <artifactId>ethereumj-core</artifactId>
     <version>1.8.1-RELEASE</version>
   </dependency>

或者你的Gradle項(xiàng)目:

repositories {
       mavenCentral()
       jcenter()
       maven { url "https://dl.bintray.com/ethereum/maven/" }
   }
   compile "org.ethereum:ethereumj-core:1.8.+"

作為你項(xiàng)目的起點(diǎn),任何一個(gè)項(xiàng)目都可以以下列方式啟動(dòng):

git clone https://github.com/ether-camp/ethereumj.starter
./gradlew run

檢查你的本地區(qū)塊鏈如何同步使用:

 curl -w "\n" -X GET http://localhost:8080/bestBlock

構(gòu)建可執(zhí)行的JAR

git clone https://github.com/ethereum/ethereumj
cd ethereumj
cp ethereumj-core/src/main/resources/ethereumj.conf ethereumj-core/src/main/resources/user.conf
vim ethereumj-core/src/main/resources/user.conf # adjust user.conf to your needs
./gradlew clean fatJar
java -jar ethereumj-core/build/libs/ethereumj-core-*-all.jar

從命令行運(yùn)行:

> git clone https://github.com/ethereum/ethereumj
> cd ethereumj
> ./gradlew run [-PmainClass=<sample class>]

可以運(yùn)行任意一個(gè)測(cè)試示例:

./gradlew run -PmainClass=org.ethereum.samples.BasicSample
./gradlew run -PmainClass=org.ethereum.samples.FollowAccount
./gradlew run -PmainClass=org.ethereum.samples.PendingStateSample
./gradlew run -PmainClass=org.ethereum.samples.PriceFeedSample
./gradlew run -PmainClass=org.ethereum.samples.PrivateMinerSample
./gradlew run -PmainClass=org.ethereum.samples.TestNetSample
./gradlew run -PmainClass=org.ethereum.samples.TransactionBomb

快照構(gòu)建

請(qǐng)注意,快照不穩(wěn)定,目前正在開(kāi)發(fā)中!如果你還想嘗試一下:

  • https://oss.jfrog.org/libs-snapshot/添加為構(gòu)建腳本的存儲(chǔ)庫(kù)。
  • 添加依賴(lài)項(xiàng)org.ethereum:ethereumj-core:${VERSION}${VERSION}位置的值是1.9.0-SNAPSHOT。

示例如下:

<repository>
    <id>jfrog-snapshots</id>
    <name>oss.jfrog.org</name>
    <url>https://oss.jfrog.org/libs-snapshot/</url>
    <snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- ... -->
<dependency>
   <groupId>org.ethereum</groupId>
   <artifactId>ethereumj-core</artifactId>
   <version>1.9.0-SNAPSHOT</version>
</dependency>

將項(xiàng)目導(dǎo)入IntelliJ IDEA:

> git clone https://github.com/ethereum/ethereumj
> cd ethereumj
> gradlew build

IDEA:

  • File -> New -> Project from existing sources......
  • 選擇 ethereumj/build.gradle
  • 對(duì)話框“Import Project from gradle”:點(diǎn)擊“ok”
  • 在構(gòu)建之后運(yùn)行org.ethereum.Start,org.ethereum.samples.*之一或創(chuàng)建自己的主程序。

配置EthereumJ

有關(guān)所有現(xiàn)有選項(xiàng),其描述和默認(rèn)值的參考,你可以參考默認(rèn)配置ethereumj.conf(你可以在jar庫(kù)或源代碼ethereum-core/src/main/resources目錄中找到它),要重新設(shè)置所需的選項(xiàng),你可以使用以下方法之一:

  • 把你的選項(xiàng)放到<working dir>/config/ethereumj.conf文件中
  • user.conf放到classpath的啟動(dòng)目錄中(作為一個(gè)資源)
  • 將你的選項(xiàng)放在任何文件中并通過(guò)它提供-Dethereumj.conf.file=<your config>
  • 編程通過(guò)SystemProperties.CONFIG.override*()使用
  • 編程重寫(xiě)Spring SystemPropertiesbean來(lái)使用

請(qǐng)注意,不需要將所有選項(xiàng)都放在自定義配置中,只需要放置你需要修改的那些選項(xiàng)。

如果你希望盡快的使用java開(kāi)始以太坊的開(kāi)發(fā),可以選擇web3j類(lèi)庫(kù),它封裝實(shí)現(xiàn)了絕大部分web3的功能,十分好用:

java以太坊教程,主要是針對(duì)java和android程序員進(jìn)行區(qū)塊鏈以太坊開(kāi)發(fā)的web3j詳解。

另外分享下之前其他語(yǔ)言的以太坊課程鏈接:

  • 以太坊教程,主要介紹智能合約與dapp應(yīng)用開(kāi)發(fā),適合入門(mén)。
  • 以太坊開(kāi)發(fā),主要是介紹使用node.js、mongodb、區(qū)塊鏈、ipfs實(shí)現(xiàn)去中心化電商DApp實(shí)戰(zhàn),適合進(jìn)階。
  • python以太坊,主要是針對(duì)python工程師使用web3.py進(jìn)行區(qū)塊鏈以太坊開(kāi)發(fā)的詳解。
  • php以太坊,主要是介紹使用php進(jìn)行智能合約開(kāi)發(fā)交互,進(jìn)行賬號(hào)創(chuàng)建、交易、轉(zhuǎn)賬、代幣開(kāi)發(fā)以及過(guò)濾器和事件等內(nèi)容。
  • C#以太坊,主要講解如何使用C#開(kāi)發(fā)基于.Net的以太坊應(yīng)用,包括賬戶管理、狀態(tài)與交易、智能合約開(kāi)發(fā)與交互、過(guò)濾器和事件等。

匯智網(wǎng)原創(chuàng)翻譯,轉(zhuǎn)載請(qǐng)標(biāo)明出處。這里是原文

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容