This commit is contained in:
Gautham Ganesh Elango 2020-07-01 15:05:35 +10:00
parent c8b92bc287
commit f6b5fac2f8
No known key found for this signature in database
GPG Key ID: 420E32E35B3FDBA2
2 changed files with 13 additions and 1 deletions

View File

@ -50,7 +50,7 @@ $ mkdir $HOME/work
## Setup btcd rpcclient
We will be using the rpcclient that comes with btcd, a Bitcoin implementation written in Go. Although btcd was originally designed to work with the btcd Bitcoin full node, it also works with Bitcoin core. It has some quirks which we will be looking at. We can use ```go get``` to download it:
We will be using the rpcclient that comes with btcd, a Bitcoin implementation written in Go. Although rpcclient was originally designed to work with the btcd Bitcoin full node, it also works with Bitcoin core. It has some quirks which we will be looking at. We can use ```go get``` to download it:
```
$ go get github.com/btcsuite/btcd/rpcclient

View File

@ -31,6 +31,7 @@ $ export BITCOIND_PORT=18332
```
> **WARNING:** Obviously, you'd never put set your password in an environmental variable in a production environment.
> **MAINNET VS TESTNET:** The port would be 8332 for a mainnet setup.
You can now verify everything is working correctly:
@ -98,6 +99,17 @@ You can run it with ```$ node server.js```. You should get an output similar to
0000000000000083d29c524d4cfc257adfab8fa9b6f0d207d1d0f1b63e1de11e
```
The BCRPC functions can accept inputs. For example, ```getBlockHash``` takes ```blockCount.result``` as an input. The result of the BCRPC functions is a JSON object containing information about any errors and the id of the request. When accessing our result, we add ```.result``` to the end of it to specify that we are interested in the actual result, not information about errors. This is what output of the above example would look like if we replaced ```console.log(blockCount.result);``` and ```console.log(hash.result);``` with ```console.log(blockCount);``` and ```console.log(hash);```, respectively:
```
{ result: 1774686, error: null, id: null }
{
result: '00000000000000d980c495a2b7addf09bb0a9c78b5b199c8e965ee54753fa5da',
error: null,
id: null
}
```
## Look Up Your Wallet
You can also lookup your wallet and view your balance, transaction count et cetera: