以太坊常见问题和错误

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

php如何调用以太坊JSON-RPC接口创建钱包?

首先下载安装geth,下载地址如下:

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

安装后会在安装目录生成一个geth.exe,需要使用命令行工具来运行它。

初始化

geth --datadir "chain" init piccgenesis.json

piccgenesis.json文件:

{
  "config": {
        "chainId": 33,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "coinbase" : "0x0000000000000000000000000000000000000000",
    "difficulty" : "0x4",
    "extraData" : "",
    "gasLimit" : "0xffffffff",
    "nonce" : "0x0000000000000042",
    "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp" : "0x00",
    "alloc": { }
}
}

设置json-rpc

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

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

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

php 调用json-rpc

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

也可以参考以下几个链接:

https://github.com/ethereum/wiki/wiki/JSON-RPC
https://github.com/paritytech/parity/wiki/JSONRPC-personal-module

go-ethereum APIs:

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal
http://www.cocoachina.com/blockchain/20180125/22019.html

PHP本文用的Thinkphp中的jsonrpc类:

public function index(){
vendor('jsonRPC.jsonRPCClient');
$client = new \jsonRPCClient('http://localhost:8534');
dump($client->personal_newAccount("111111"));
}

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