首页 > 最新资讯 > 行业博客

以太坊钱包JSON-RPC接口创建及对接数字货币交易平台方法

2018-05-24 00:19:22 云思盈科 已读

以太坊钱包JSON-RPC接口创建及对接数字货币交易平台方法(thinkphp)


1,下载安装geth,下载地址如下:

http://ethfans.org/wikis/Wallet-Mirror

进入后点击,下载和安装都很快,本文安装的是windows版

2,运行geth,安装之后会在安装目录生成一个geth.exe,需要使用cmd来运行它

第一步先初始化一下:

  1. geth --datadir "chain" init piccgenesis.json 

piccgenesis.json文件
 

  1.   "config": { 

  2.         "chainId": 33, 

  3.         "homesteadBlock": 0, 

  4.         "eip155Block": 0, 

  5.         "eip158Block": 0 

  6.     }, 

  7.     "coinbase" : "0x0000000000000000000000000000000000000000"

  8.     "difficulty" : "0x4"

  9.     "extraData" : ""

  10.     "gasLimit" : "0xffffffff"

  11.     "nonce" : "0x0000000000000042"

  12.     "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000"

  13.     "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000"

  14.     "timestamp" : "0x00"

  15.     "alloc": { } 

第二步设置rpc并开启rpc接口,rpc地址为127.0.0.1:8534
 

  1. geth --rpc --rpccorsdomain * --datadir ./mychain -rpcport 8534 --port 30308 --identity test --networkid 123456999 --rpcaddr 0.0.0.0 --rpcapi admin,miner,db,eth,net,web3,personal --nodiscover console 

注:这里用的是测试网络,不需要同步所有区块,如果要正试应用需要一台linux服务器,开启主网同步所有区块,在打开并设置rpc

3,geth安装完成,rpc接口开启,下面就该用php调用geth的rpc方法了

也可以参考以下几个链接
 

  1. https://github.com/ethereum/wiki/wiki/JSON-RPC 

  2. https://github.com/paritytech/parity/wiki/JSONRPC-personal-module 

go-ethereum APIs
 

  1. https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal 

  2. http://www.cocoachina.com/blockchain/20180125/22019.html 

PHP本文用的Thinkphp中的jsonrpc类
 

  1. public function index(){ 

  2. vendor('jsonRPC.jsonRPCClient'); 

  3. $client = new \jsonRPCClient('http://localhost:8534'); 

  4. dump($client->personal_newAccount("123456")); 

一个钱包就创建好了,123456是密码,是personal_newAccount这个方法的参数,还有其它rpc方法参考上面的连接




文章出自云思盈科 http://www.yunthink.com

Copyright © 2014-2017 云思盈科 ICP备案:鲁ICP备14007705号-1 企业微信

增值电信业务许可证号:鲁B2-20220173

山东省潍坊市高新区软件园·光谷工馆A座612室