<p>Enable <code>txindex=1</code> in your bitcoin.conf (You'll need to rebuild the database as the transaction index is normally not maintained, start using <code>-reindex</code> to do so), and use the <code>getrawtransaction</code> call to request information about any transaction (it won't work for the genesis block's coinbase transaction though, it's a special case).</p>

<p>Note that this will only give you raw transaction data (you can add a <code>1</code> argument after the call to have it decoded instead of in hexadecimal notation), but it cannot know the payment amount or fees, for example.</p>

CC BY-SA 3.0
2013-06-21T17:01:35.450Z
Just to be clear: You cannot get information about payment amount or fees - at all? :-) Because that sounds quite wrong (Blockchain.info does this).
I am reindexing the blockchain now :-)
Lars Holdgaard
CC BY-SA 3.0
2013-06-21T17:26:03.883Z
You can compute the fee yourself by subtracting the amounts of all outputs from the sum of the amounts of all inputs (which you'll have to look up through getrawtransaction too). You can of course see the amount of a particular output, but unless the address it is to is yours, you can't know for example which is change and which is the payment. Wallets are designed to do all that for you, if you bypass them, you need to do things manually.
Pieter Wuille
CC BY-SA 3.0
2013-06-21T20:03:19.337Z
Thanks a lot. I also want other people to look at "decoderawtransaction" -> GREAT function. Thanks again :-)
Lars Holdgaard
CC BY-SA 3.0
2015-08-26T12:55:08.070Z
I was able to use `bitcoin-cli decoderawtransaction $(bitcoin-cli getrawtransaction txid)` to get transaction details. Seems that the answer to use `txindex=1` is out of date?
jangorecki
CC BY-SA 3.0
2015-08-26T16:43:05.150Z
jangorecki: getrawtransaction always works on transactions that are not yet completely spent.
Pieter Wuille
CC BY-SA 4.0
2019-07-24T16:08:24.370Z
this answer is correct for litecoin too.
kodmanyagha
CC BY-SA 4.0
2022-02-16T18:36:53.150Z
@jangorecki `txindex=1` is needed for transactions that are not pertinent to your wallet
Ron
CC BY-SA 3.0
2013-06-21T16:46:57.103Z
2013-06-21T16:46:57.103Z
Pieter Wuille
<p>I am playing around with Bitcoin-qt. I want to iterate all blocks and all their transactions.</p>

<p>So far I've been able to get a list of all tx's in the blocks I want to. Now I want to get information about the transaction: Amount, confirmations and so forth.</p>

<p>However, when I use the <code>gettransaction</code> method of the Bitcoin-qt API, it seems I can only get transactions from my own wallet.</p>

<p>For instance, I cannot say, because I get the error "<code>Invalid or non-wallet transaction id (code -5)</code> ":</p>

<pre><code>gettransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098
</code></pre>

<p>However, when I have a TX of one of my own transactions, I get a correct response.</p>

<p>My code</p>

<pre><code>public void AddBtcTransaction(string hash)
        {
            List&lt;string&gt; parameters = new List&lt;string&gt;();
            parameters.Add(hash);

            var data = RequestServer("gettransaction", parameters);
            int i = 0;
        }

        public string RequestServer(string methodName, List&lt;string&gt; parameters)
        {
            string respVal = string.Empty;

            var rawRequest = GetRawRequest();
            JObject joe = new JObject();
            joe.Add(new JProperty("jsonrpc", "1.0"));
            joe.Add(new JProperty("id", "1"));
            joe.Add(new JProperty("method", methodName));

            JArray props = new JArray();
            foreach (var parameter in parameters)
            {
                props.Add(parameter);
            }

            joe.Add(new JProperty("params", props));

            // serialize json for the request
            string s = JsonConvert.SerializeObject(joe);
            byte[] byteArray = Encoding.UTF8.GetBytes(s);
            rawRequest.ContentLength = byteArray.Length;
            Stream dataStream = rawRequest.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            StreamReader streamReader = null;
            try
            {
                WebResponse webResponse = rawRequest.GetResponse();

                streamReader = new StreamReader(webResponse.GetResponseStream(), true);

                respVal = streamReader.ReadToEnd();
                var data = JsonConvert.DeserializeObject(respVal).ToString();
                return data;
            }
            catch (Exception exp)
            {

            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();        
                }

            }
            return string.Empty;
        }

        private HttpWebRequest GetRawRequest()
        {

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ServerIp);
            webRequest.Credentials = new NetworkCredential(UserName, Password);
            /// important, otherwise the service can't desirialse your request properly
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method = "POST";

            return webRequest;
        }
</code></pre>

<p>Any idea about how I would get information about transactions outside my wallet?</p>

<transactions><development><bitcoin-core><json-rpc>
Get non-wallet transactions using bitcoin rpc (gettransaction)
Lars Holdgaard
# Get non-wallet transactions using bitcoin rpc (gettransaction)

(Asked by: username_0 on 2013-06-21)

I am playing around with Bitcoin-qt. I want to iterate all blocks and all their transactions.

So far I've been able to get a list of all tx's in the blocks I want to. Now I want to get information about the transaction: Amount, confirmations and so forth.

However, when I use the `gettransaction` method of the Bitcoin-qt API, it seems I can only get transactions from my own wallet.

For instance, I cannot say, because I get the error "`Invalid or non-wallet transaction id (code -5)` ":

```
gettransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098

```

However, when I have a TX of one of my own transactions, I get a correct response.

My code

```
public void AddBtcTransaction(string hash)
        {
            List<string> parameters = new List<string>();
            parameters.Add(hash);

            var data = RequestServer("gettransaction", parameters);
            int i = 0;
        }

        public string RequestServer(string methodName, List<string> parameters)
        {
            string respVal = string.Empty;

            var rawRequest = GetRawRequest();
            JObject joe = new JObject();
            joe.Add(new JProperty("jsonrpc", "1.0"));
            joe.Add(new JProperty("id", "1"));
            joe.Add(new JProperty("method", methodName));

            JArray props = new JArray();
            foreach (var parameter in parameters)
            {
                props.Add(parameter);
            }

            joe.Add(new JProperty("params", props));

            // serialize json for the request
            string s = JsonConvert.SerializeObject(joe);
            byte[] byteArray = Encoding.UTF8.GetBytes(s);
            rawRequest.ContentLength = byteArray.Length;
            Stream dataStream = rawRequest.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            StreamReader streamReader = null;
            try
            {
                WebResponse webResponse = rawRequest.GetResponse();

                streamReader = new StreamReader(webResponse.GetResponseStream(), true);

                respVal = streamReader.ReadToEnd();
                var data = JsonConvert.DeserializeObject(respVal).ToString();
                return data;
            }
            catch (Exception exp)
            {

            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();        
                }

            }
            return string.Empty;
        }

        private HttpWebRequest GetRawRequest()
        {

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ServerIp);
            webRequest.Credentials = new NetworkCredential(UserName, Password);
            /// important, otherwise the service can't desirialse your request properly
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method = "POST";

            return webRequest;
        }

```

Any idea about how I would get information about transactions outside my wallet?

**Tags:** transactions, development, bitcoin-core, json-rpc


---

## 1 answers

### Answer by username_1 on 2013-06-21. Score: 33 | Accepted answer

Enable `txindex=1` in your bitcoin.conf (You'll need to rebuild the database as the transaction index is normally not maintained, start using `-reindex` to do so), and use the `getrawtransaction` call to request information about any transaction (it won't work for the genesis block's coinbase transaction though, it's a special case).

Note that this will only give you raw transaction data (you can add a `1` argument after the call to have it decoded instead of in hexadecimal notation), but it cannot know the payment amount or fees, for example.

> **Comments:**
> **username_0**: Just to be clear: You cannot get information about payment amount or fees - at all? :-) Because that sounds quite wrong (Blockchain.info does this). I am reindexing the blockchain now :-)  
> **username_1**: You can compute the fee yourself by subtracting the amounts of all outputs from the sum of the amounts of all inputs (which you'll have to look up through getrawtransaction too). You can of course see the amount of a particular output, but unless the address it is to is yours, you can't know for example which is change and which is the payment. Wallets are designed to do all that for you, if you bypass them, you need to do things manually.  
> **username_0**: Thanks a lot. I also want other people to look at "decoderawtransaction" -> GREAT function. Thanks again :-)  
> **username_2**: I was able to use `bitcoin-cli decoderawtransaction $(bitcoin-cli getrawtransaction txid)` to get transaction details. Seems that the answer to use `txindex=1` is out of date?  
> **username_1**: username_2: getrawtransaction always works on transactions that are not yet completely spent.  
> **username_3**: this answer is correct for litecoin too.  
> **username_4**: @username_2 `txindex=1` is needed for transactions that are not pertinent to your wallet  

---

