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)明出處。這里是原文