BTC(비트코인)
Install
비트코인 공식 사이트에서 최신 버전을 확인 후 다운로드
core 설치
기본값으로 설치를 하고, 블록 크기를 2GB로 제한하는 옵션을 그대로 유지합니다.(중요)
이 옵션을 해제하면 307GB 블록을 모두 저장을 하기때문에 용량을 많이 차지하고, 시간도 오래 걸립니다.
설치 후 실행을 하면 블록 헤더정보를 다운로드하고, 이후에 블록을 다운받아서 처리를 합니다.
블록을 순차적으로 처리하면서 무결성 검사를 합니다.
bitcoin.conf
Edit your bitcoin.conf.
Uncomment regtest=0 and enable it: regtest=1
Uncomment rpcuser=alice and replace the value with your username.
Uncomment rpcpassword=... and replace the value with the password you got from rpcauth.
Uncomment rpcauth=bob:... and replace the value with the line you got from rpcauth.
(Optional) Append datadir=<unpacked_folder>/data to the end of the file, where <unpacked_folder> is the absolute path to your unpacked folder.
Running
테스트 환경
테스트환경 에서 실행하기 위해서는 -regtest를 입력하면 된다.
bitcoin-cli getbalance "*" // 실제환경
bitcoin-cli -regtest getbalance "*" // 테스트 환경
Start
bitcoind를 통해 bitcoin-core 를 실행시키고 bitcoin-cli를 통해 bitcoind의 json-rcp 인터페이스를 호출할수 있도록 해줍니다.
# bitcoind -daemon
Bitcoin server starting
RCP
bitcoin-cli help
getblockchaininfo
현재의 block 정보를 가져온다.
bitcoin-cli getblockchaininfo
아래의 정보중 blocks가 현재의 block이고 전체 블록을 보기위해서는 아래 링크를 참조해 주세요
{
"chain": "main",
"blocks": 891863,
"headers": 502820,
..........
"size_on_disk": 15334078733,
"pruned": false,
}
getnewaddress
account 생성
bitcoin-cli -regtest getnewaddress "label | accountname"
generatetoaddress
테스트용 비트코인 생성을 특정 위에서 만들어진 주소로 전송
bitcoin-cli -regtest generatetoaddress 1 '2N9ETRE1b57K3rvhxpzqrz6aQ2bJ79QxxLG'
listtransactions
모든 주소(*)에 대해 트랜잭션 리스트 10개 가져오기
bitcoin-cli -regtest listtransactions "*" 10
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listtransactions", "params": ["*", 10]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "listtransactions", "params": ["*", 20, 100]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
getbalance
모든 주소에 대해 잔고 확인
bitcoin-cli -regtest getbalance "*"
sendtoaddress
특정주소로 비트코인 보내기
bitcoin-cli -regtest sendtoaddress [address] [btc]
bitcoin-cli -regtest sendtoaddress 2Mvxxxxxxxxxxxxxxxxyg 100
getreceivedbyaddress
bitcoin-cli -regtest getreceivedbyaddress "2MtMLpHxcBe2uvedBGtxMr9yY2vbFqFvEqX"