All Projects → zhangbincheng1997 → Ethereum

zhangbincheng1997 / Ethereum

以太坊开发 HelloWorld for Java

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Ethereum

Geth Jsonrpc Php Client
API client lib for communication with geth (go-ethereum) node.
Stars: ✭ 64 (-66.49%)
Mutual labels:  ethereum, geth
Ethnode
Run an Ethereum node (Geth or Openethereum) for development
Stars: ✭ 74 (-61.26%)
Mutual labels:  ethereum, geth
Core Geth
A highly configurable Go implementation of the Ethereum protocol.
Stars: ✭ 66 (-65.45%)
Mutual labels:  ethereum, geth
Ethdroid
Easy-to-use Ethereum Geth wrapper for Android
Stars: ✭ 47 (-75.39%)
Mutual labels:  ethereum, geth
Web3 By Example
Node.js with Web3 javascript examples for getting basic information (transactions, balances, network stats, and tokens) from the Ethereum blockchain.
Stars: ✭ 156 (-18.32%)
Mutual labels:  ethereum, geth
Violationsystem
Ethernum ViolationSystem
Stars: ✭ 50 (-73.82%)
Mutual labels:  ethereum, geth
Nethereum
Ethereum .Net cross platform integration library
Stars: ✭ 1,191 (+523.56%)
Mutual labels:  ethereum, geth
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions.
Stars: ✭ 237 (+24.08%)
Mutual labels:  ethereum, geth
Geth Dev
A Docker Image to create a set of mining, local Ethereum nodes for development
Stars: ✭ 109 (-42.93%)
Mutual labels:  ethereum, geth
Eth Indexer
An Ethereum project to crawl blockchain states into database
Stars: ✭ 98 (-48.69%)
Mutual labels:  ethereum, geth
Go Ethereum
Official Go implementation of the Ethereum protocol
Stars: ✭ 34,169 (+17789.53%)
Mutual labels:  ethereum, geth
Tokenbalance
Simple Ethereum API to get your ERC20 Token Balance along with useful information
Stars: ✭ 163 (-14.66%)
Mutual labels:  ethereum, geth
Ethermint Archive
Ethereum on Tendermint using Cosmos-SDK!
Stars: ✭ 667 (+249.21%)
Mutual labels:  ethereum, geth
Dagger.js
Simple library to connect with dagger server and manage subscriptions for Ethereum Blockchain.
Stars: ✭ 179 (-6.28%)
Mutual labels:  ethereum, geth
Baseline
The Baseline Protocol is an open source initiative that combines advances in cryptography, messaging, and blockchain to execute secure and private business processes at low cost via the public Ethereum Mainnet. The protocol will enable confidential and complex collaboration between enterprises without leaving any sensitive data on-chain
Stars: ✭ 479 (+150.79%)
Mutual labels:  ethereum, geth
Ico Contracts
🎉 ICO Contracts of the ALIS.
Stars: ✭ 69 (-63.87%)
Mutual labels:  ethereum, geth
Myetherapi
An API by MyEtherWallet. ETH / Ropsten / JSON RPC / Web3
Stars: ✭ 95 (-50.26%)
Mutual labels:  ethereum, geth
Crowdfunding
基于区块链(以太坊)技术的安全众筹系统
Stars: ✭ 159 (-16.75%)
Mutual labels:  ethereum, geth
Go Ethereum Hdwallet
Ethereum HD Wallet derivations in Go (golang)
Stars: ✭ 178 (-6.81%)
Mutual labels:  ethereum, geth
Tbtc
Trustlessly tokenized Bitcoin on Ethereum ;)
Stars: ✭ 182 (-4.71%)
Mutual labels:  ethereum

以太坊开发 HelloWorld for Java

😄 更新版本,支持插件。

Geth下载

  1. 官方下载: https://ethereum.github.io/go-ethereum/downloads/
  2. 国内镜像: https://ethfans.org/wikis/Ethereum-Geth-Mirror
  3. 其他安装方式: https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum
***** CentOS *****
$ yum -y update
$ yum -y install golang
$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum/
$ make geth
$ ls -al build/bin/geth
如果出错,尝试命令:
$ mv /usr/local/include/iconv.h /usr/local/include/iconv.h.back

初始以太坊

$ geth init genesis.json
自动生成 ~/.ethereum
.
├── geth
│   ├── chaindata
│   │   ├── 000001.log
│   │   ├── CURRENT
│   │   ├── LOCK
│   │   ├── LOG
│   │   └── MANIFEST-000000
│   └── lightchaindata
│       ├── 000001.log
│       ├── CURRENT
│       ├── LOCK
│       ├── LOG
│       └── MANIFEST-000000
├── history
└── keystore

启动以太坊

$ startup.bat # Windows
$ startup.sh # Linux

geth --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --rpccorsdomain "*" --rpcapi "personal,db,eth,net,web3" --networkid 666666 console
--rpc Enable the HTTP-RPC server
--rpcaddr HTTP-RPC server listening interface (default: localhost)
--rpcport HTTP-RPC server listening port (default: 8545)
--rpccorsdomain Comma separated list of domains from which to accept cross origin requests (browser enforced)
--rpcapi API's offered over the HTTP-RPC interface (default: eth,net,web3)
--networkid 区块链ID-私链
--console 命令行模式

钱包

# 查询账户
> eth.accounts
# 创建账户
> personal.newAccount("123456") # 密码123456
# 查询余额
> eth.getBalance(eth.accounts[0])

挖矿

# 开始挖矿 (一个线程挖矿,多线程会很卡)
> miner.start(1)
# 停止挖矿
> miner.stop()

编写合约

  1. 中文文档 http://www.tryblockchain.org/
  2. 英文文档 https://solidity.readthedocs.io/
  3. 在线测试 https://remix.ethereum.org/

部署合约

  1. 方式一 - remix编译 + geth部署

alt text

# 解锁用户
> personal.unlockAccount(eth.account[0])
# 输入代码
> var helloworldContract = web3.eth.contract(......); var helloworld = helloworldContract.new(......)

console: INFO [MM-dd|HH:mm:ss] Submitted contract creation              fullhash=0x...... contract=0x......
  1. 方式二 - web3j ↓

Web3j 轻量级的以太坊开发库 for Java

alt text

  1. Web3j依赖:https://github.com/web3j/web3j/
<dependencies>
	<dependency>
		<groupId>org.web3j</groupId>
		<artifactId>core</artifactId>
		<version>4.5.11</version>
	</dependency>
</dependencies>
  1. Web3j插件:https://github.com/web3j/web3j-maven-plugin
<plugin>
    <groupId>org.web3j</groupId>
    <artifactId>web3j-maven-plugin</artifactId>
    <version>4.5.11</version>
    <configuration>
        <soliditySourceFiles/>
    </configuration>
</plugin>
  1. 运行插件:Plugins->web3j:generate-sources
resources/HelloWorld.sol ----> org.web3j.model.HelloWorld
  1. 部署合约:main/java/com/example/demo/HelloWorldDeploy.java
HelloWorld contract = HelloWorld.deploy(web3j, credentials, new DefaultGasProvider()).send();
System.out.println("getContractAddress : " + contract.getContractAddress());
// rewrite: contractAddress ----> application.properties
  1. 加载合约:main/java/com/example/demo/HelloWorldMain.java
HelloWorld contract = HelloWorld.load(Constants.ADDRESS, web3j, credentials, new DefaultGasProvider());
System.out.println("getContractAddress : " + contract.getContractAddress());
  1. 项目结构
--com.example.demo.util
----Constants.java 常量

--com.example.demo.test
----ClientVersionTest.java 版本
----TransferEthTest.java 转账
----TransactionGetTest.java Web3j 原生调用合约的 get 方法
----TransactionSetTest.java Web3j 原生调用合约的 set 方法
----FilterTest.java 过滤器

--com.example.demo.contract
----HelloWorldDeploy.java 部署合约
----HelloWorldMain.java 加载合约

Maven镜像

C:\Users\zhang\.m2\settings.xml

<mirrors>
    <mirror>
        <id>ali-maven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
    <mirror>
        <id>jboss-maven</id>
        <name>jBoss maven</name>
        <url>http://repository.jboss.org/nexus/content/groups/public</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

错误信息

Usage of API documented as @since 1.8+

解决方法设置如下:

alt text

Error:java: Compilation failed: internal java compiler error

解决方法设置如下:

alt text

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].