Giter Club home page Giter Club logo

ethereum's Introduction

以太坊开发 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 ↓

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

ethereum's People

Contributors

zhangbincheng1997 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethereum's Issues

您好

您好 我是今天突然接到一个任务 需要做这方面的一个功能 想请问一下 如果我有多人注册 怎么获取不同的hash码呢 好像api上没有生成hash码的接口

前辈你好!请教一个关于同步以太坊钱包数据格式问题

起因是我同步了以太坊钱包数据,生成了很多的ldb文件与cdat文件,我想读取.ldb与.cdat里面的合约数据,不过不知道怎样打开。下载下来的文件夹是这样的
image
看到您在文章中有例举·
image
这与我同步下来的几个文件很像,请问
000001.log
CURRENT

we couldn't estimate the gas

after click deploy,error tip like this:"it seems this transaction will fail,we couldn't estimate the gas",it may consume all the gas you provide.(钱包挖矿所得4665 ETHER)
钱包界面里没有gas设置,只有genesis.json里有 "gasLimit" : "0x2fefd8",.
想看下你的genesis.json

private static final String BINARY = "0x6060604052341561000f57600080fd5b60d38061001d6000396000f3006060604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c14606e575b600080fd5b3415605857600080fd5b606c60048080359060200190919050506094565b005b3415607857600080fd5b607e609e565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a72305820b287ea3878f6f6cc6e7e3885be10bd9172b2074fbdc32fbfc8f7edd3f683e8d90029";

这个binary值是哪里来的呢

这个命令是干嘛的?

make geth后
ln -s build/bin/geth /usr/bin/geth # 软链接
这个命令是干嘛的?ln: failed to create symbolic link '/usr/bin/geth': File exists

Ethereum

这个java版的helloworld的三种方式都ok,但既然是跑在以太坊上的,那怎么和本地的以太坊EthereumJ java版源码发生联系呢?我想在EthereumJ里打下log看看流程,比如挖矿和交易确认的代码是怎么确认的,两个项目是要在ide里建立依赖关系吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.