顯示具有 乙太坊 標籤的文章。 顯示所有文章
顯示具有 乙太坊 標籤的文章。 顯示所有文章

2018年8月30日

安裝Parity筆記

安裝rust

curl https://sh.rustup.rs -sSf | sh

安裝parity

  
git clone https://github.com/paritytech/parity-ethereum
cd parity-ethereum
git checkout stable //只安裝stable版本
cargo build --release --features final

或直接下載 binary :
https://github.com/paritytech/parity-ethereum/releases

缺少套件

  • libudev.h
yum install systemd-devel
  • cmake3:
下載cmak3 source (https://cmake.org/)
./bootstrap --prefix=/usr/local
make
make install

執行

./parity --jsonrpc-interface=w.x.y.z --jsonrpc-apis=eth,web3,personal,net,traces --jsonrpc-cors=all --chain=ropsten --jsonrpc-threads=1 --tracing=on
interface 表示要綁在哪一張網卡上

參數說明

  • --jsonrpc-interface 綁定rpc service的IP
  • --jsonrpc-apis 5 RPC支援的API
  • --jsonrpc-cors 允許CORS的網域
  • --chain 使用的ether網路名稱
  • --jsonrpc-threads RPC服務耗用CPU的資源
  • --tracing=on 開啟trace模式
  • --geth geth相容模式,讓RCP的指令可以跟geth相容一點點
  • --warp 使用snapshot方式同步最近的資料,之後有空的時候會慢慢同步前面的資料

config

  • parity也可以使用設定檔,設定檔位址在~/.local/share/io.parity.ethereum/config.toml
[parity]
mode = "active"
mode_timeout = 300
mode_alarm = 3600
auto_update = "critical"
release_track = "current"
public_node = false
no_download = false
no_consensus = false
no_persistent_txqueue = false

chain = "kovan"
base_path = "$HOME/.local/share/io.parity.ethereum"
db_path = "$HOME/.local/share/io.parity.ethereum/chains"
keys_path = "$HOME/.local/share/io.parity.ethereum/keys"
identity = ""
light = false

[rpc]
disable = false
port = 8545
interface = "w.x.y.z"
cors = ["all"]
apis = ["web3", "eth", "net", "personal", "traces"]
hosts = ["none"]
server_threads = 1

[websockets]
disable = true

[ipc]
disable = true

[footprint]
tracing = "on"

[misc]
logging = "own_tx=trace"
log_file = "/var/log/parity.log"
color = true

問題排除

  • 錯誤訊息 : TraceDB resync required
    修改~/.local/share/io.parity.ethereum/chains/test/user_defaults,把tracing改為true
  • 當啟動tracing模式的時候將無法使用warp sync

RPC 執行範例

  • Command
curl --data '{"method":"trace_filter","params":[{"fromBlock":"0x1","toBlock":"latest","fromAddress":["0x..............."]"]}],"id":1,"jsonrpc":"2.0"}' -H "Content-Type: application/json" -X POST w.x.y.z:8545
curl -X POST --data '{"jsonrpc": "2.0", "id":"curltest", "method": "eth_getTransactionByHash", "params": ["0x..............."] }' -H 'content-type: application/json' http://w.x.y.z:8545
  • Result
{"jsonrpc":"2.0","result":[{....}],"id":1}

2018年4月17日

乙太坊筆記 – 建立虛擬鏈

  • 初始化私有ETH網路,可以用puppeth指令產生創世區塊的json內容
geth --datadir “./privatechain” init custom_genesis.json
  • 建立兩個節點,這樣之後一個節點可以提供rpc服務,一個可以用來挖礦
  • 如果是要在同一台機器上建立不同的節點,所有的節點都必須在獨立的目錄底下運作

        {
          "config": {
            "chainId": 657,
            "homesteadBlock": 1,
            "eip150Block": 2,
            "eip150Hash": "0x000000000000000000000000000000000...",
            "eip155Block": 3,
            "eip158Block": 3,
            "byzantiumBlock": 4,
            "ethash": {}
          },
          "nonce": "0x0",
          "timestamp": "0x5ad4459f",
          "extraData": "0x000000000000000000000000000000000...",
          "gasLimit": "0x47b760",
          "difficulty": "0x80000",
          "mixHash": "0x000000000000000000000000000000000...",
          "coinbase": "0x000000000000000000000000000000000...",
          "alloc": {
            "xxxx": {
              "balance": "0x2000000000000000000000000000000000..."
            }
          },
          "number": "0x0",
          "gasUsed": "0x0",
          "parentHash": "0x000000000000000000000000000000000..."
        }
        
  • custom_genesis.json 裡面可以放一些錢給測試用的帳號:
    "alloc": {
               "0xxxxxx":
                   {"balance": "10000"}
            }
        
  • 在console啟動節點
    • 常用參數
      • --networkid 為啟動在哪個網路id,避免衝突
      • --datadir 為指定區塊鏈資料位置
      • --ipcdisable 不加這個參數的話在本地啟動多個服務會出現access deny(CentOS沒這個問題,windows才會)
      • --config 後面可以加上自定義的TOML檔案來設定參數
      • 在<datadir>/geth/底下的static-nodes.json可以定義要和這個node同步的peers
      • 指令後面加上 dumpconfig 可以把設定值匯出成toml檔案
    • node1(監聽2000 port) :
    geth --datadir ./privatechain --networkid 1510 
    --port 2000 --ipcdisable console
            
    • node2(監聽2001 port) :
    geth --datadir ./privatechain --networkid 1510 
    --port 2001 --ipcdisable console
            
  • 讓兩個節點可以互相溝通
    • 在node1執行 admin.nodeInfo
      在輸出的結果中找到enode 資訊,會有類似底下的格式 :
      enode://xxxxx@[::]:2000,把enode的xxxx抄下來
    • 回到node2,執行
      admin.addPeer("enode://xxxxx@127.0.0.1:2000")
      127.0.0.1:2000 是node1監聽的位置
      照相同的步驟在node1把node2的端點加進去
      執行 admin.peers 檢查一下是否兩個node都互相連結了
    • 每次重啟node都需要重新做一次,可以直接toml設定檔來寫入設定,避免每次都要重新加
  • 在console模式底下的指令:
    • 查看帳戶
      eth.accounts

    • 建立帳號,設定密碼 123456
      personal.newAccount("123456")

      產生的私鑰會放在keystore目錄裡面
    • 解鎖帳號,這樣就不需要輸入密鑰也能交易
      personal.unlockAccount('0xxxxxx','pass')

  • 啟動RPC服務
    geth --datadir ./privatechain --networkid 1510 --rpc

會開始監聽 8545 port



  • 挖礦
    geth --datadir ./privatechain --networkid 1510 
            --port 2001 --ipcdisable --mine --minerthreads=1 
    --etherbase=0xxxxx 

    • etherbase 用來指定挖礦的coin要歸戶給哪個帳戶
    • minerthreads 表示要用幾個thread來挖礦



  • 交易
    Ethereum EVM的單位是Wei
    1 Ether = 1,000,000,000,000,000,000 Wei
    交易費用 = 實際用到的Gas * Gas Price
    如果Gas Limit不夠,交易將會無法完成,但是手續費會被扣掉
    如果Gas足夠,剩下的Gas會釋出所以不會多收手續費
  • 注意事項
    • 不管是要在哪一個node對虛擬鏈下交易指令,都必須在那一台node上啟動挖礦,否則交易都會卡在pending裡面(有時候在各個node可以查到交易成功,但是用了第三方套件例如metamask則會無法顯示正確交易結果)
    • 有時候挖礦指令會當掉,必須先
      miner.stop()
      miner.start(1)
      重新開啟
  • 每個node最後執行的指令
    • node 1 :
      geth --datadir ./privatechain --networkid 1510 
              --port 2000 --config config.toml --rpc 
      --rpcaddr x.x.x.x --rpccorsdomain "*" console
    • node 2:
      geth --datadir ./privatechain --networkid 1510 
              --port 2001 --config config.toml --mine 
      --minerthreads=1 --etherbase=0xxxxx console
  • 精選文章

    利用Selenium IDE進行UI測試

    安裝與執行 Selenium IDE是Firefox的一個plugin,用來做UI的自動測試:下載網址為http://docs.seleniumhq.org/download/ 安裝後,點一下firefox 的工具 -> Selenium IDE ,就會...