From 51c232f841cedf0444cfec6de249efbc2a86ba8f Mon Sep 17 00:00:00 2001 From: Parsa Hosseini Date: Fri, 9 Jul 2021 22:29:11 +0430 Subject: [PATCH 1/4] Change parameters in create address section. --- 04_4__Interlude_Using_Curl.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/04_4__Interlude_Using_Curl.md b/04_4__Interlude_Using_Curl.md index 676ce35..6609445 100644 --- a/04_4__Interlude_Using_Curl.md +++ b/04_4__Interlude_Using_Curl.md @@ -218,17 +218,19 @@ This is almost exactly the same output that you receive when you type `bitcoin-c After you know where your funds are, the next step in crafting a transaction is to get a change address. By now you've probably got the hang of this, and you know that for simple RPC commands, all you need to do is adjust the `method` is the `curl` command: ``` -$ curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawchangeaddress", "params": ["legacy"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.' +$ curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawchangeaddress", "params": ["", "legacy"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.' { "result": "mrSqN37TPs89GcidSZTvXmMzjxoJZ6RKoz", "error": null, "id": "curltest" } +> **WARNING:** The parameters order is important when you are sending RPC commands using curl. For example here, if we had sent `"params": ["legacy"]` instead of `"params": ["", "legacy"]`, we would get a `bech32` address with a label of `"legacy"` instead of a `legacy` address, so pay attention to the order. + ``` At this point, we can even revert to our standard practice of saving results to variables with additional help from `jq`: ``` -$ changeaddress=$(curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawchangeaddress", "params": ["legacy"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.result') +$ changeaddress=$(curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawchangeaddress", "params": ["", "legacy"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.result') $ echo $changeaddress mqdfnjgWr2r3sCCeuTDfe8fJ1CnycF2e6R ``` From c242393c5e1488ca3b7135db418e55d0f720d99f Mon Sep 17 00:00:00 2001 From: Parsa Hosseini Date: Fri, 9 Jul 2021 22:34:46 +0430 Subject: [PATCH 2/4] Fix typo --- 04_4__Interlude_Using_Curl.md | 1 + 1 file changed, 1 insertion(+) diff --git a/04_4__Interlude_Using_Curl.md b/04_4__Interlude_Using_Curl.md index 6609445..ba15aa0 100644 --- a/04_4__Interlude_Using_Curl.md +++ b/04_4__Interlude_Using_Curl.md @@ -224,6 +224,7 @@ $ curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc" "error": null, "id": "curltest" } +``` > **WARNING:** The parameters order is important when you are sending RPC commands using curl. For example here, if we had sent `"params": ["legacy"]` instead of `"params": ["", "legacy"]`, we would get a `bech32` address with a label of `"legacy"` instead of a `legacy` address, so pay attention to the order. From e1ef3c8467eb47c66eb4b9c56d67d98788d22539 Mon Sep 17 00:00:00 2001 From: Parsa Hosseini Date: Fri, 9 Jul 2021 22:36:24 +0430 Subject: [PATCH 3/4] Fix typo --- 04_4__Interlude_Using_Curl.md | 1 - 1 file changed, 1 deletion(-) diff --git a/04_4__Interlude_Using_Curl.md b/04_4__Interlude_Using_Curl.md index ba15aa0..0ad2629 100644 --- a/04_4__Interlude_Using_Curl.md +++ b/04_4__Interlude_Using_Curl.md @@ -228,7 +228,6 @@ $ curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc" > **WARNING:** The parameters order is important when you are sending RPC commands using curl. For example here, if we had sent `"params": ["legacy"]` instead of `"params": ["", "legacy"]`, we would get a `bech32` address with a label of `"legacy"` instead of a `legacy` address, so pay attention to the order. -``` At this point, we can even revert to our standard practice of saving results to variables with additional help from `jq`: ``` $ changeaddress=$(curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawchangeaddress", "params": ["", "legacy"] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ | jq -r '.result') From 17a3735e738557153fbcbeeca30013f3c16f63f3 Mon Sep 17 00:00:00 2001 From: Parsa Hosseini Date: Fri, 9 Jul 2021 23:20:24 +0430 Subject: [PATCH 4/4] Fix a code block in get information section. --- 04_4__Interlude_Using_Curl.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/04_4__Interlude_Using_Curl.md b/04_4__Interlude_Using_Curl.md index 0ad2629..3463164 100644 --- a/04_4__Interlude_Using_Curl.md +++ b/04_4__Interlude_Using_Curl.md @@ -111,9 +111,11 @@ Here's what some parameter arrays will look like: You can now send your first `curl` command by accessing the `getmininginfo` RPC: ``` $ curl --user StandUp:8eaf562eaf45c33c3328bc66008f2dd1 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getmininginfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332/ -{"result":{"blocks":1772428,"difficulty":10178811.40698772,"networkhashps":91963587385939.06,"pooledtx":61,"chain":"test","warnings":"Warning: unknown new rules activated (versionbit 28)"},"error":null,"id":"curltest"}``` -Note that we provided the method, `getmininginfo`, and the parameter, `[]`, but that everything else was the standard `curl` command line. +{"result":{"blocks":1772428,"difficulty":10178811.40698772,"networkhashps":91963587385939.06,"pooledtx":61,"chain":"test","warnings":"Warning: unknown new rules activated (versionbit 28)"},"error":null,"id":"curltest"} ``` + +Note that we provided the method, `getmininginfo`, and the parameter, `[]`, but that everything else was the standard `curl` command line. + > **WARNING:** If you get a result like "Failed to connect to 127.0.0.1 port 8332: Connection refused", be sure that a line like `rpcallowip=127.0.0.1` is in your ~/.bitcoin/bitcoin.conf. If things still don't work, be sure that you're allowing access to port 18332 (or 8332) from localhost. Our standard setup from [Chapter Two: Creating a Bitcoin-Core VPS](02_0_Setting_Up_a_Bitcoin-Core_VPS.md) should do all of this. The result is another JSON array, which is unfortunately ugly to read if you're using `curl` by hand. Fortunately, you can clean it up simply by piping it through `jq`: