Bitcoin Forum
May 29, 2024, 08:14:05 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: JSON error  (Read 278 times)
columbo (OP)
Jr. Member
*
Offline Offline

Activity: 45
Merit: 1


View Profile
November 08, 2017, 01:15:04 PM
 #1

I have a bitcoin core setup under a specific linux user name: xbt.
I would like to run bitcoin-cli with the root user. For this, I wrote a shell script, xbt-bitcoin.sh:

#!/bin/bash

/home/xbt/bitcoin-0.15.0/bin/bitcoin-cli -conf=/home/xbt/.bitcoin/bitcoin.conf $@

So basically this shell script pass all arguments to my bitcoin-cli and it is working very well for simple commands like:
./xbt-bitcoin.sh getbalance
./sbt-bitcoin.sh getnewaddress
./xbt-bitcoin.sh getbalance "AccountName"
etc.

However, I have issues with more complex commands like:

.xbt-bitcoin.sh sendmany "" "{\"address1\":0.02,\"address2\":0.01}" 1 ""
I get an error like:

"error code: -1
error message:
JSON value is not an object as expected"

I guess something is wrong with the way I pass the arguments via the shell script but I can't figure it out how to resolve this.
What can be wrong here?
aleksej996
Sr. Member
****
Offline Offline

Activity: 490
Merit: 389


Do not trust the government


View Profile
November 09, 2017, 08:08:27 PM
 #2

Perhaps for that command bitcoin-cli requires to be passed quotation marks and the shell strips them away and only passes the string inside of them.
Maybe try adding a backslash to all of your quotation marks and if the bitcoin-cli requires to be passed a backslash for some quotation marks then add those with the double backslash as well.

Example:

Your command
Code:
./xbt-bitcoin.sh sendmany "" "{\"address1\":0.02,\"address2\":0.01}" 1 ""
might pass arguments to bitcoin-cli as this
Code:
.xbt-bitcoin.sh sendmany  {"address1":0.02,"address2":0.01}" 1 
The way it might work
Code:
.xbt-bitcoin.sh sendmany \"\" \"{\\\"address1\\\":0.02,\\\"address2\\\":0.01}\" 1 \"\"

Just and idea you can try.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!