php如何調用以太坊JSON-RPC接口建立錢包

首先下載安裝geth,下載地址以下:php

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

安裝後會在安裝目錄生成一個geth.exe,須要使用命令行工具來運行它。linux

初始化

geth --datadir "chain" init piccgenesis.json

piccgenesis.json文件:git

{
  "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:github

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。web

php 調用json-rpc

geth安裝完成,rpc接口開啓,下面就該用php調用geth的rpc方法了json

也能夠參考如下幾個連接:api

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方法參考上面的鏈接。

若是想系統的學習php開發以太坊的話推薦一個很受歡迎的在線互動教程: php以太坊,主要是介紹使用php進行智能合約開發交互,進行帳號建立、交易、轉帳、代幣開發以及過濾器和事件等內容。

相關文章
相關標籤/搜索