Bitcoin error parsing json

0 votes

 I have written a bash script to simulate the transactions between the nodes. The code is as follows:

#!/bin/bash

MAX_NODES=2

MY_PATH=/home/ubuntu/test

CLIENT=/usr/local/bin/bitcoin-cli

declare -a addr

function fcomp() {

        /usr/bin/awk -v n1=$1 -v n2=$2 'BEGIN{ if (n1>n2) exit 0; exit 1}'

}

json="'{"

#get addresses to send

for ((i = 1; i <= MAX_NODES; i++));

do

    addr[$i-1]="$($CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i/ getnewaddress myaccount)"

    if [ "$i" -lt "$MAX_NODES" ]

    then

        json="$json\"${addr[$i-1]}\":0.00001, "

    else

        json="$json\"${addr[$i-1]}\":0.00001"

    fi

done

json="$json}'"

echo $json

#loop to send money to other nodes

for ((i = 1; i <= MAX_NODES; i++));

do

        balance=`$CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i/ getbalance`

        if fcomp $balance 0.002; then

                $CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i sendmany myaccount $json

    fi

done

echo json output:

'{"mj2FrDhEomSzyQtRoGY78oVRPcQs5L5o95":0.00001, "mkxnkT3kx9dsFS8V3qYydpL1o5F5MfwCvM":0.00001}'

I get the following error:

error: Error parsing JSON:'{"mj2FrDhEomSzyQtRoGY78oVRPcQs5L5o95":0.00001,
Aug 22, 2018 in Blockchain by slayer
• 29,370 points
1,505 views

1 answer to this question.

0 votes

Make these changes in your code:

json="'{" to json="{" , json="$json}'" to "json="$json}" and $CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i sendmany myaccount $json to $CLIENT -regtest -rpcport=$((16500 + $i)) -datadir=$MY_PATH/$i sendmany myaccount "$json"

Apparently, json was not being passed to bitcoin-cli. After making these changes, your error will be gone.

answered Aug 22, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Bitcoin transaction “amount is below the current minimum” error

I went through the code and the ...READ MORE

answered Aug 21, 2018 in Blockchain by slayer
• 29,370 points
696 views
0 votes
2 answers

Angular Bitcoin error: "Error trying to diff '[object Object]'"

There are two approaches to this: 1. You ...READ MORE

answered Sep 4, 2018 in Blockchain by slayer
• 29,370 points
13,899 views
+1 vote
3 answers
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,295 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
924 views
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
2,382 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,942 views
0 votes
1 answer

Bitcoin: parsing Blockchain API using JSON

Because you only add one address to ...READ MORE

answered Aug 22, 2018 in Blockchain by digger
• 26,740 points
3,329 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP