New FAMILUG

The PyMiers

Sunday 12 March 2017

Bitcoin Core với JSON-RPC

Update: Cảm ơn các thành viên trong Pymi đã đọc và cho những đóng góp  ý kiến để bài viết đc hoàn thiện.

Đây là một bài hướng dẫn cài Bitcoin Core và thiết lập JSON-RPC cho Bitcoin Core version v0.14.0. Nếu bạn chưa biết gì về Bitcoin Core có thể tìm hiểu ở phần link tham khảo. Server sử dụng Ubuntu 14.04 (cấu hình tối thiểu 2GB RAM, 125 GB ổ cứng), có thể tham khảo về cấu hình server bitcoin tại đây.

1. Add repo của Bitcoin Core

Chạy lệnh sau:
apt-get install -y software-properties-common && \
add-apt-repository ppa:bitcoin/bitcoin -y && \
apt-get update

2. Cài đặt Bitcoin Core cùng các thư việc hỗ trợ

apt-get install build-essential libtool autotools-dev autoconf \
libssl-dev libboost-all-dev bitcoind -y

3. Tạo thư mục mà Bitcoin Core sử dụng để lưu dữ liệu và config(mặc định bitcoin sử dụng ~/.bitcoin)

mkdir ~/.bitcoin

4. Tạo file cấu hình cho Bitcoin Core

tạo file ~/.bitcoin/bitcoind.conf với nội dung sau


# username cho client sử dụng để connect Bitcoin Core qua JRPC
rpcuser=testuser
# mật khẩu để xác thực cho user
rpcpassword=test123456
# port mà Bitcoin Core lắng nghe request với protocol JSON-RPC
rpcport=8332
# địa chỉ cho phép connect đến Bitcoin Core
rpcallowip=127.0.0.1
# bật chế độ listen JSON-RPC cho Bitcoin Core
server=1

5. Run Bitcoin Core

bitcoind -daemon

conf: tham số chỉ đường dẫn tới file config

daemon: tham số để bitcoind chạy ở chế độ background

6. Test Bitcoin Core


curl --user testuser:test123456 --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getinfo","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:8332

response
{
    "result": {
        "paytxfee": 0.0,
        "protocolversion": 70015,
        "version": 140000,
        "relayfee": 1e-05,
        "proxy": "",
        "balance": 0.0,
        "walletversion": 130000,
        "timeoffset": 0,
        "keypoolsize": 100,
        "connections": 2,
        "difficulty": 1,
        "keypoololdest": 1489029112,
        "errors": "",
        "testnet": false,
        "blocks": 64
    },
    "error": null,
    "id": "curltext"
}


  1. Bitcoin Wikipedia
  2. Bitcoin Wiki
  3. Bitcoin Website
  4. Bitcoin Stackexchange

No comments:

Post a Comment