0% found this document useful (0 votes)
217 views5 pages

1.2BitcoinLab New

This document describes how to build programs that interact with Bitcoin using the bitcoin-cli command line interface and regtest mode. It provides instructions on starting bitcoind in regtest mode to create a private blockchain, generating new addresses, transactions, and blocks, and exploring other bitcoin-cli commands.

Uploaded by

fintech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
217 views5 pages

1.2BitcoinLab New

This document describes how to build programs that interact with Bitcoin using the bitcoin-cli command line interface and regtest mode. It provides instructions on starting bitcoind in regtest mode to create a private blockchain, generating new addresses, transactions, and blocks, and exploring other bitcoin-cli commands.

Uploaded by

fintech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Bitcoin Lab

bitcoin-qt provides a combination full Bitcoin peer and wallet frontend.


bitcoind is more useful for programming: it provides a full peer which you can interact with through
RPCs to port 8332 (or 18332 for testnet).
bitcoin-cli allows you to send RPC commands to bitcoind from the command line.
Reference: https://bitcoin.org/en/developer-examples#regtest-mode

I. build programs using Bitcoin


# This worked on Ubuntu kernal 4.15.0-48

1.Downlaod latest version of bitcoin unzip using command


tar -xvzf bitcoin-0.19.0.1-i686-pc-linux-gnu.tar.gz

2. Go to bitcoin bin location


/home/divakar/bitcoin-0.19.0.1/bin

3. To Start Bitcoin Core’s regression test mode


It Instantly create a brand-new private block chain. You have complete control over the
environment.
./bitcoind -regtest -daemon

4. To create new address


./bitcoin-cli -regtest getnewaddress
It will give an address n1G8jLb71oypxPtNtTWkAdMo1rkp7oLj6V
To store address in new variable
New_Address=n1G8jLb71oypxPtNtTWkAdMo1rkp7oLj6V
To Display New_Address
echo $New_Address
n1G8jLb71oypxPtNtTWkAdMo1rkp7oLj6V
5. To Start bitcoind in regtest mode to create a private block chain.
./bitcoin-cli -regtest generatetoaddress 101 $New_Address
It generates 101 blocks only available in regtest mode.
It give a reward of 50 blocks after confirmation of 100 blocks.
We generate 101 blocks to get access to the coinbase transaction from block #1

6 . To get current balance


./bitcoin-cli -regtest getbalance
II. Transactions
1. To create new address
./bitcoin-cli -regtest getnewaddress
It will give an address n1G8jLb71oypxPtNtTWkAdMo1rkp7oLj6V
To store address in new variable
New_Address=n1G8jLb71oypxPtNtTWkAdMo1rkp7oLj6V
To Display New_Address
echo $New_Address
n1G8jLb71oypxPtNtTWkAdMo1rkp7oLj6V

2. Send 10 bitcoins to the address. It will return hex string is the transaction identifier
./bitcoin-cli -regtest sendtoaddress $NEW_ADDRESS 10.00

3. To see only showing confirmed UTXOs


./bitcoin-cli -regtest listunspent

4. To see unconfirmed transactions also with the argument “0” to also display
./bitcoin-cli -regtest listunspent 0

5. Create a new block to confirm the transaction


./bitcoin-cli -regtest generate 1

6. Getting bloch Hash 0


./bitcoin-cli -regtest getblockhash 0
7. Getting block hedder information
./bitcoin-cli -regtest getblockheader HASH
(0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206)

8. Getting your own Account Address


./bitcoin-cli -regtest getaccountaddress ""

It Display your account Address


9. Get information about accounts
./bitcoin-cli -regtest getinfo

Set of other commands


getbestblockhash
getblock "hash" ( verbose )
getblockchaininfo
getblockcount
getblockhash index
getchaintips
getdifficulty
getmempoolinfo
getrawmempool ( verbose )
gettxout "txid" n ( includemempool )
gettxoutproof ["txid",...] ( blockhash )
gettxoutsetinfo
verifychain ( checklevel numblocks )
verifytxoutproof "proof"

== Control ==
getinfo
help ( "command" )
stop

== Generating ==
generate numblocks
getgenerate
setgenerate generate ( genproclimit )
== Mining ==
getblocktemplate ( "jsonrequestobject" )
getmininginfo
getnetworkhashps ( blocks height )
prioritisetransaction <txid> <priority delta> <fee delta>
submitblock "hexdata" ( "jsonparametersobject" )

== Network ==
addnode "node" "add|remove|onetry"
getaddednodeinfo dns ( "node" )
getconnectioncount
getnettotals
getnetworkinfo
getpeerinfo
ping

== Rawtransactions ==
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...}
decoderawtransaction "hexstring"
decodescript "hex"
getrawtransaction "txid" ( verbose )
sendrawtransaction "hexstring" ( allowhighfees )
signrawtransaction "hexstring"
( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...]
["privatekey1",...] sighashtype )

== Util ==
createmultisig nrequired ["key",...]
estimatefee nblocks
estimatepriority nblocks
validateaddress "bitcoinaddress"
verifymessage "bitcoinaddress" "signature" "message"

== Wallet ==
addmultisigaddress nrequired ["key",...] ( "account" )
backupwallet "destination"
dumpprivkey "bitcoinaddress"
dumpwallet "filename"
encryptwallet "passphrase"
getaccount "bitcoinaddress"
getaccountaddress "account"
getaddressesbyaccount "account"
getbalance ( "account" minconf includeWatchonly )
getnewaddress ( "account" )
getrawchangeaddress
getreceivedbyaccount "account" ( minconf )
getreceivedbyaddress "bitcoinaddress" ( minconf )
gettransaction "txid" ( includeWatchonly )
getunconfirmedbalance
getwalletinfo
importaddress "address" ( "label" rescan )
importprivkey "bitcoinprivkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaccounts ( minconf includeWatchonly)
listaddressgroupings
listlockunspent
listreceivedbyaccount ( minconf includeempty includeWatchonly)
listreceivedbyaddress ( minconf includeempty includeWatchonly)
listsinceblock ( "blockhash" target-confirmations includeWatchonly)
listtransactions ( "account" count from includeWatchonly)
listunspent ( minconf maxconf ["address",...] )
lockunspent unlock [{"txid":"txid","vout":n},...]
move "fromaccount" "toaccount" amount ( minconf "comment" )
sendfrom "fromaccount" "tobitcoinaddress" amount ( minconf "comment" "comment-
to" )
sendmany "fromaccount" {"address":amount,...} ( minconf "comment"
["address",...] )
sendtoaddress "bitcoinaddress" amount ( "comment" "comment-to"
subtractfeefromamount )
setaccount "bitcoinaddress" "account"
settxfee amount
signmessage "bitcoinaddress" "message"

You might also like