<p>I am  not 100 % sure of this answer;
The input is stored in tx_in table and the corresponding inputs addresses can be found by</p>
<p><code>select * from tx_out where tx_id in ( select tx_in_id from tx_in where tx_out_id =133903);</code></p>
<p>you are getting the address which are inputs to the transaction.</p>

CC BY-SA 4.0
2021-09-27T16:27:36.850Z
2021-09-27T16:35:41.837Z
2021-09-27T16:35:41.837Z
raghu
<p>Query:</p>
<pre><code>select prev_tx_out.address sender
     , this_tx_out.address receiver
     , this_tx_out.value

  from tx this_tx

 inner join tx_out this_tx_out
    on this_tx_out.tx_id = this_tx.id

 inner join tx_in this_tx_in
    on this_tx_in.tx_in_id = this_tx.id

 inner join tx_out prev_tx_out
    on prev_tx_out.tx_id = this_tx_in.tx_out_id
   and prev_tx_out.index = this_tx_in.tx_out_index

 where this_tx.id = 133903
;
</code></pre>
<p>Result:</p>
<pre><code>                                                  sender                                                  |                                                 receiver                                                 |     value     
----------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+---------------
 DdzFFzCqrhsycjyjN1UGhehYVs7ZcCfoUR8PNF7QaXgYtNcEci68gLuFrbioBTyvDPW6ztiEDYPZC3jXH9DqjEgXhzLLGUL5hdENMVF4 | DdzFFzCqrhskf5Bho1HFpjzFGcVG3avzBMBkP4DUHMJMuqaNmPrt5Cnf1GUxQ3gFxFrbZUHsrxgqUf3fkn5NxjHSDh67SfuKHGLcYYuV | 2936699288244
 DdzFFzCqrhsycjyjN1UGhehYVs7ZcCfoUR8PNF7QaXgYtNcEci68gLuFrbioBTyvDPW6ztiEDYPZC3jXH9DqjEgXhzLLGUL5hdENMVF4 | DdzFFzCqrht3JYLq1Cc9Y3EeyZvTwzwuu5QZCJqbmjFVMj23miQeSMESfJoSb4f1NNJL9ti1nJryGSB1VK7yFbzkRtcEjamaSvj6LP8k |  100000000000
</code></pre>

CC BY-SA 4.0
2022-05-10T08:43:25.720Z
2022-05-10T08:43:25.720Z
grim_i_am
<p>Remember that a transaction always spends all the transaction input.</p>
<p>Unless the <code>total (tx_out.value) + fee == tx_in.value</code> there will be two <code>tx_out</code> entries, one for the recipient and the other is the change output that goes back to the sending wallet.</p>

CC BY-SA 4.0
2022-11-30T02:33:41.793Z
2022-11-30T02:33:41.793Z
Erik de Castro Lopo
<p>Using the code of @grim_i_am</p>
<ol>
<li>for transaction 34369121, I have the following.
Am I right to understand that in this transaction, 1 sender send to multiple receiver with different amount? If so, why at the receiver, the receiver's address are duplicated?</li>
</ol>
<p><a href="https://i.sstatic.net/nYhIM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nYhIM.png" alt="transaction 34369121" /></a></p>
<ol start="2">
<li>For transaction id 34368652,
<a href="https://i.sstatic.net/7FrPn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7FrPn.png" alt="enter image description here" /></a>
the sender and receiver are multiple. this is normal?
How can 2 sender can send at the same time? I am not quite understand.</li>
</ol>

CC BY-SA 4.0
2022-06-18T14:54:53.847Z
Check the  code used by [Koios](https://api.koios.rest) for getting tx inputs and outputs [here](https://github.com/cardano-community/guild-operators/blob/alpha/files/grest/rpc/transactions/tx_utxos.sql)
RdLrT
CC BY-SA 4.0
2022-07-07T20:39:16.473Z
a cardano transaction can have multiple inputs and multiple outputs. In the same way that the multiple outputs can go to different addresses, the multiple inputs can come from different addresses too. As long as the transaction is signed by all the private keys of all the input addresses, the transaction is valid.
  
Also, a single wallet can have multiple derived addresses. So what you are seeing as multiple senders might actually be the same sender. You can confirm this by checking whether the staking_address_id values of all of the sender addresses are the same.
grim_i_am
CC BY-SA 4.0
2022-06-18T06:39:43.167Z
2022-06-18T06:39:43.167Z
cdt
<p>I am needing help with this. I queried the rows whose tx_id = 133903 from tx_out table from postgres.</p>
<pre><code>select * from tx_out where tx_id = 133903;
</code></pre>
<p>and I got two rows having two different indices 0 and 1. The result is below in JSON format.</p>
<pre><code>[
  {
    &quot;id&quot;: 240155,
    &quot;tx_id&quot;: 133903,
    &quot;index&quot;: 0,
    &quot;address&quot;: &quot;DdzFFzCqrhskf5Bho1HFpjzFGcVG3avzBMBkP4DUHMJMuqaNmPrt5Cnf1GUxQ3gFxFrbZUHsrxgqUf3fkn5NxjHSDh67SfuKHGLcYYuV&quot;,
    &quot;address_raw&quot;: &quot;E'\\\\x82D818584283581C3490095835CC47B0D182A0DC054D49816D9782FA42D3D26EFF4F613EA101581E581C740E27451628BDD32329FC359C8FC1C1A48FE25B94908AB8ABB577A1001A7E3A51E8'&quot;,
    &quot;payment_cred&quot;: null,
    &quot;stake_address_id&quot;: null,
    &quot;value&quot;: 2936699288244,
    &quot;address_has_script&quot;: false,
    &quot;data_hash&quot;: null
  },
  {
    &quot;id&quot;: 240156,
    &quot;tx_id&quot;: 133903,
    &quot;index&quot;: 1,
    &quot;address&quot;: &quot;DdzFFzCqrht3JYLq1Cc9Y3EeyZvTwzwuu5QZCJqbmjFVMj23miQeSMESfJoSb4f1NNJL9ti1nJryGSB1VK7yFbzkRtcEjamaSvj6LP8k&quot;,
    &quot;address_raw&quot;: &quot;E'\\\\x82D818584283581CB3CC4806AB502B2EC4FFD82CDA50BF4E5465769B6BCB6C0692C6F797A101581E581CCA3E553C9C63C562EE05D443E8D3D451372D66B450379B9002540A9B001A88AF5021'&quot;,
    &quot;payment_cred&quot;: null,
    &quot;stake_address_id&quot;: null,
    &quot;value&quot;: 100000000000,
    &quot;address_has_script&quot;: false,
    &quot;data_hash&quot;: null
  }
]
</code></pre>
<p>Correct me if I am wrong but the address field in the tx_out table basically is the receiver right? I want to get the sender's address. How do I find out the sender of this transaction? I am having some hard time figuring this out. Basically I want to create a table that contains the address of sender and receiver and amount for all the transaction ever recorded in the postgres table.</p>

<cardano-db-sync>
Cardano db sync sender and receiver address confusion
# Cardano db sync sender and receiver address confusion

(Asked by: username_0 on 2021-09-27)

I am needing help with this. I queried the rows whose tx_id = 133903 from tx_out table from postgres.
select * from tx_out where tx_id = 133903;

and I got two rows having two different indices 0 and 1. The result is below in JSON format.
[
  {
    "id": 240155,
    "tx_id": 133903,
    "index": 0,
    "address": "DdzFFzCqrhskf5Bho1HFpjzFGcVG3avzBMBkP4DUHMJMuqaNmPrt5Cnf1GUxQ3gFxFrbZUHsrxgqUf3fkn5NxjHSDh67SfuKHGLcYYuV",
    "address_raw": "E'\\\\x82D818584283581C3490095835CC47B0D182A0DC054D49816D9782FA42D3D26EFF4F613EA101581E581C740E27451628BDD32329FC359C8FC1C1A48FE25B94908AB8ABB577A1001A7E3A51E8'",
    "payment_cred": null,
    "stake_address_id": null,
    "value": 2936699288244,
    "address_has_script": false,
    "data_hash": null
  },
  {
    "id": 240156,
    "tx_id": 133903,
    "index": 1,
    "address": "DdzFFzCqrht3JYLq1Cc9Y3EeyZvTwzwuu5QZCJqbmjFVMj23miQeSMESfJoSb4f1NNJL9ti1nJryGSB1VK7yFbzkRtcEjamaSvj6LP8k",
    "address_raw": "E'\\\\x82D818584283581CB3CC4806AB502B2EC4FFD82CDA50BF4E5465769B6BCB6C0692C6F797A101581E581CCA3E553C9C63C562EE05D443E8D3D451372D66B450379B9002540A9B001A88AF5021'",
    "payment_cred": null,
    "stake_address_id": null,
    "value": 100000000000,
    "address_has_script": false,
    "data_hash": null
  }
]

Correct me if I am wrong but the address field in the tx_out table basically is the receiver right? I want to get the sender's address. How do I find out the sender of this transaction? I am having some hard time figuring this out. Basically I want to create a table that contains the address of sender and receiver and amount for all the transaction ever recorded in the postgres table.

**Tags:** cardano-db-sync

---

## 4 answers

### Answer by username_1 on 2021-09-27. Score: 3

I am not 100 % sure of this answer;
The input is stored in tx\_in table and the corresponding inputs addresses can be found by

`select * from tx_out where tx_id in ( select tx_in_id from tx_in where tx_out_id =133903);`

you are getting the address which are inputs to the transaction.


---

### Answer by username_2 on 2022-05-10. Score: 1

Query:
select prev_tx_out.address sender
     , this_tx_out.address receiver
     , this_tx_out.value

  from tx this_tx

 inner join tx_out this_tx_out
    on this_tx_out.tx_id = this_tx.id

 inner join tx_in this_tx_in
    on this_tx_in.tx_in_id = this_tx.id

 inner join tx_out prev_tx_out
    on prev_tx_out.tx_id = this_tx_in.tx_out_id
   and prev_tx_out.index = this_tx_in.tx_out_index

 where this_tx.id = 133903
;

Result:
                                                  sender                                                  |                                                 receiver                                                 |     value     
----------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------+---------------
 DdzFFzCqrhsycjyjN1UGhehYVs7ZcCfoUR8PNF7QaXgYtNcEci68gLuFrbioBTyvDPW6ztiEDYPZC3jXH9DqjEgXhzLLGUL5hdENMVF4 | DdzFFzCqrhskf5Bho1HFpjzFGcVG3avzBMBkP4DUHMJMuqaNmPrt5Cnf1GUxQ3gFxFrbZUHsrxgqUf3fkn5NxjHSDh67SfuKHGLcYYuV | 2936699288244
 DdzFFzCqrhsycjyjN1UGhehYVs7ZcCfoUR8PNF7QaXgYtNcEci68gLuFrbioBTyvDPW6ztiEDYPZC3jXH9DqjEgXhzLLGUL5hdENMVF4 | DdzFFzCqrht3JYLq1Cc9Y3EeyZvTwzwuu5QZCJqbmjFVMj23miQeSMESfJoSb4f1NNJL9ti1nJryGSB1VK7yFbzkRtcEjamaSvj6LP8k |  100000000000


---

### Answer by username_3 on 2022-11-30. Score: 1

Remember that a transaction always spends all the transaction input.

Unless the `total (tx_out.value) + fee == tx_in.value` there will be two `tx_out` entries, one for the recipient and the other is the change output that goes back to the sending wallet.


---

### Answer by username_4 on 2022-06-18. Score: 0

Using the code of @grim\_i\_am

1. for transaction 34369121, I have the following.
   Am I right to understand that in this transaction, 1 sender send to multiple receiver with different amount? If so, why at the receiver, the receiver's address are duplicated?

[![transaction 34369121](https://i.sstatic.net/nYhIM.png)](https://i.sstatic.net/nYhIM.png)

2. For transaction id 34368652,
   [![enter image description here](https://i.sstatic.net/7FrPn.png)](https://i.sstatic.net/7FrPn.png)
   the sender and receiver are multiple. this is normal?
   How can 2 sender can send at the same time? I am not quite understand.

> **Comments:**
> **username_5**: Check the  code used by [Koios](https://api.koios.rest) for getting tx inputs and outputs [here](https://github.com/cardano-community/guild-operators/blob/alpha/files/grest/rpc/transactions/tx_utxos.sql)  
> **username_2**: a cardano transaction can have multiple inputs and multiple outputs. In the same way that the multiple outputs can go to different addresses, the multiple inputs can come from different addresses too. As long as the transaction is signed by all the private keys of all the input addresses, the transaction is valid.    Also, a single wallet can have multiple derived addresses. So what you are seeing as multiple senders might actually be the same sender. You can confirm this by checking whether the staking_address_id values of all of the sender addresses are the same.  

---

