JSON-RPC signrawtransaction returns false when using private keys

1

Introduction

This is a list of the monerod daemon RPC calls, their inputs and outputs, and examples of each.

Many RPC calls use the daemon's JSON RPC interface while others use their own interfaces, as demonstrated below.

Note: "atomic units" refer to the smallest fraction of 1 XMR according to the monerod implementation. 1 XMR = 1e12 atomic units.

JSON RPC Methods:

Other RPC Methods:

JSON RPC Methods

The majority of monerod RPC calls use the daemon's json_rpc interface to request various bits of information. These methods all follow a similar structure, for example:

IP=127.0.0.1 PORT=18081 METHOD='getblockheaderbyheight' PARAMS='{"height":912345}' curl \ -X POST http://$IP:$PORT/json_rpc \ -d '{"jsonrpc":"2.0","id":"0","method":"'$METHOD'","params":'$PARAMS'}' \ -H 'Content-Type: application/json'

Some methods include parameters, while others do not. Examples of each JSON RPC method follow.

...
0 0
2

I had a heck of a time getting anything to work. I hope this helps others.

To get the list of active players:

curl --user foo:bar --header 'Content-Type: application/json' --data-binary '{ "id": 1, "jsonrpc": "2.0", "method": "Player.GetActivePlayers" }' 'http://192.168.1.127/jsonrpc'

Response can be something like:

{"id":1,"jsonrpc":"2.0","result":[{"playerid":2,"type":"picture"}]}

To stop player #2:

curl --user foo:bar --header 'Content-Type: application/json' --data-binary '{ "id": 1, "jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": 2 } }' 'http://192.168.1.127/jsonrpc'

Response is something like:

{"id":1,"jsonrpc":"2.0","result":"OK"}

The playerid is what was returned for playerid in the GetActivePlayers.

To start a slideshow:

curl --user foo:bar --header 'Content-Type: application/json' --data-binary '{ "id": 1, "jsonrpc": "2.0", "method": "Player.Open", "params": {"item": {...

0 0
3

JSON-RPC is a lightweight Remote Procedure Call protocol that utilizes JSON for its messaging envelopes. This JSON-RPC implementation follows PHP's » SoapServer API. This means, in a typical situation, you will simply:

Zend_Json_Server utilizes Zend_Server_Reflection to perform reflection on any attached classes or functions, and uses that information to build both the SMD and enforce method call signatures. As such, it is imperative that any attached functions and/or class methods have full PHP docblocks documenting, minimally:

Zend_Json_Server listens for POST requests only at this time; fortunately, most JSON-RPC client implementations in the wild at the time of this writing will only POST requests as it is. This makes it simple to utilize the same server end point to both handle requests as well as to deliver the service SMD, as is shown in the next example.

First, let's define a class we...

0 0
4

The samples above work with HTTP requests. Here's a variant that works with TCP (the Nil class is just an empty class used for requests with no return value):

using System; using System.Collections.Generic; using System.IO; using System.Net; using Newtonsoft.Json.Linq; using AustinHarris.JsonRpc; using System.Linq; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Reactive.Concurrency; using System.Net.Sockets; using System.Text; namespace JsonRpc { public class JsonRpcClient { private static object idLock = new object(); private static int id = 0; public Encoding encoding { get; set; } public JsonRpcClient(IPEndPoint serviceEndpoint, Encoding encoding) { this.serviceEndPoint = serviceEndpoint; this.encoding = encoding; } private static Stream CopyAndClose(Stream inputStream) { const int readSize = 256; byte[] buffer = new byte[readSize]; MemoryStream ms = new MemoryStream(); int...
0 0
5

This is a simple JSON RPC Client for Android. I wrote this class for one of my Android projects that needs to connect to external JSON RPC API. Feel free to use it, download the files at the bottom of this post..;)

JSON RPC Client

package net.londatiga.android; import net.londatiga.android.Cons; import net.londatiga.android.Debug; import net.londatiga.android.StringUtil; import java.io.InputStream; import java.util.HashMap; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.json.JSONObject; import org.json.JSONTokener; /** * Simple JSON RPC Client * * @author Lorensius W. L. T * */ public class JSONRPCClient { private String mBaseUrl; private...
0 0
6
...
0 0
7

I've been working with BitcoinLib testing various parameters on the signrawtransaction rpc call.

It's been mostly successful, however there seems to be a persisting problem when using only private keys to sign a transaction. (second optional argument of signrawtransaction call). The server replies false and returns the failed hex. I have tested the same transaction on the qt console using the same keys, and it returns true.

The wrapper employs a SignRawTransactionRequest class matching the four arguments of the rpc call.

public SignRawTransactionRequest(String rawTransactionHex) { RawTransactionHex = rawTransactionHex; Inputs = new List(); PrivateKeys = new List(); SigHashType = SignRawTransaction.SigHashType.All; }

It allows for 'inputs' and 'privatekeys' to be null, following the signrawtransaction syntax, while assuming 'sighashtype=all' unless explicitly specified otherwise.

The implementation also includes a...

0 0
8

I use the Newtonsoft.Json.Linq library as shown below to get the data. Soon, I'll be posting Strongly typed C# client libraries at http://www.coinapi.net

The main trick to getting the JSON error code is to call GetWebResponse() again in the catch method. Then return and parse the data. I've debated about including the WebException itself in the return code, but that may require too many changes. If anyone has ideas I'll be glad to take them.

var ret = InvokeMethod("getblockhash", index);

Here is the definition of InvokeMethod

public JObject InvokeMethod(string a_sMethod, params object[] a_params) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Url); webRequest.Credentials = Credentials; webRequest.ContentType = "application/json-rpc"; webRequest.Method = "POST"; JObject joe = new JObject(); joe["jsonrpc"] = "1.0"; joe["id"] = "1"; joe["method"] = a_sMethod; if (a_params != null) { if...
0 0
9

Command: signrawtransaction

null signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype ) Sign inputs for raw transaction (serialized, hex-encoded). The second optional argument (may be null) is an array of previous transaction outputs that this transaction depends on but may not yet be in the block chain. The third optional argument (may be null) is an array of base58-encoded private keys that, if given, will be the only keys used to sign the transaction. Requires wallet passphrase to be set with walletpassphrase call. Arguments: 1. "hexstring" (string, required) The transaction hex string 2. "prevtxs" (string, optional) An json array of previous dependent transaction outputs [ (json array of json objects, or 'null' if none provided) { "txid":"id", (string, required) The transaction id "vout":n, (numeric, required) The output number ...
0 0
10

Overview

The "raw transaction API" was introduced with Bitcoin-Qt/bitcoind version 0.7. It gives developers or very sophisticated end-users low-level access to transaction creation and broadcast.

JSON-RPC API

listunspent [minconf=1] [maxconf=999999]

Returns an array of unspent transaction outputs in the wallet that have between minconf and maxconf (inclusive) confirmations. Each output is a 5-element object with keys: txid, output, scriptPubKey, amount, confirmations. txid is the hexadecimal transaction id, output is which output of that transaction, scriptPubKey is the hexadecimal-encoded CScript for that output, amount is the value of that output and confirmations is the transaction's depth in the chain.

lockunspent unlock? [{"txid":txid,"vout":n},...]

Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs. A locked transaction output will not be chosen by automatic coin selection, when spending...

0 0
11

Implementation: https://github.com/bitcoin/bitcoin/pull/1456

listunspent [minconf=1] [maxconf=999999]

Returns an array of unspent transaction outputs in the wallet that have between minconf and maxconf (inclusive) confirmations. Each output is a 5-element object with keys: txid, output, scriptPubKey, amount, confirmations. txid is the hexadecimal transaction id, output is which output of that transaction, scriptPubKey is the hexadecimal-encoded CScript for that output, amount is the value of that output and confirmations is the transaction's depth in the chain.

createrawtransaction [{"txid":txid,"vout":n],...] {address:amount,...}

Create a transaction spending given inputs (array of objects containing transaction outputs to spend), sending to given address(es). Returns the hex-encoded transaction in a string. Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network.

Also note that NO...

0 0
12

MultiChain extends the Bitcoin Core API with new calls and functionality

Accessing the API

To access MultiChain’s API, use the included multichain-cli command-line tool or any other JSON-RPC client. (MultiChain is compatible with any API library developed for Bitcoin Core.) The API credentials for each blockchain are stored in the ~/.multichain/[chain-name]/multichain.conf file and read by multichain-cli. These credentials are randomly generated the first time that multichaind is called for that chain. (Note that you can change this ~/.multichain/ path using the -datadir= option, and %APPDATA%\MultiChain\ is the equivalent on Windows.)

You can use multichain-cli to send a single API command in the following form:

multichain-cli [chain-name] [command] [parameters...]

Alternatively, you can use multichain-cli in interactive mode, to send multiple commands in a single session:

multichain-cli [chain-name]

Each command is then entered...

0 0
13
# Raw transaction API example work-through # Send coins to a 2-of-3 multisig, then spend them. # # For this example, I'm using these three keypairs (public/private) # 0491bba2510912a5bd37da1fb5b1673010e43d2c6d812c514e91bfa9f2eb129e1c183329db55bd868e209aac2fbc02cb33d98fe74bf23f0c235d6126b1d8334f86 / 5JaTXbAUmfPYZFRwrYaALK48fN6sFJp4rHqq2QSXs8ucfpE4yQU # 04865c40293a680cb9c020e7b1e106d8c1916d3cef99aa431a56d253e69256dac09ef122b1a986818a7cb624532f062c1d1f8722084861c5c3291ccffef4ec6874 / 5Jb7fCeh1Wtm4yBBg3q3XbT6B525i17kVhy3vMC9AqfR6FH2qGk # 048d2455d2403e08708fc1f556002f1b6cd83f992d085097f9974ab08a28838f07896fbab08f39495e15fa6fad6edbfb1e754e35fa1c7844c41f322a1863d46213 / 5JFjmGo5Fww9p8gvx48qBYDJNAzR9pmH5S389axMtDyPT8ddqmw # First: combine the three keys into a multisig address: ./bitcoind createmultisig 2...
0 0