<blockquote>
<p>For example, how can I know that (addr1q8h ... 8k5s6cnspc) sent the token and not the other input address in this transaction? Is it actually possible to do that by only joining the tables?</p>
</blockquote>
<p>The multiple inputs of a transaction are not mapped individually to an output. All you can do is query the input UTxO to know assets associated with individual input (which is same for base currency, ADA) - you probably already have the latter part sorted, but just in case - sample example code used by <a href="https://api.koios.rest/#post-/tx_info" rel="nofollow noreferrer">koios</a> for complete transaction information can be found <a href="https://github.com/cardano-community/guild-operators/blob/alpha/files/grest/rpc/transactions/tx_info.sql" rel="nofollow noreferrer">here</a></p>
<p>In the example you mention, it is easy to deduce since all the assets were present on single address. However, if you try to look at slightly more matured wallet transaction, this will likely complicate further as you'd be associating multiple inputs containing same asset - which is true also for base asset (ADA). The logic would be the same, consider inputs used to consume in desired output, and have the remainder spent to change address.</p>

CC BY-SA 4.0
2022-07-06T03:07:02.667Z
2022-07-06T03:07:02.667Z
RdLrT
<p>I'm trying to query the token transactions using the <a href="https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/schema.md" rel="nofollow noreferrer">schemas</a> of Cardano-db-sync. When querying ADA transactions, I can easily see the input and output addresses with the values sent by joining the tx, tx_in, and tx_out tables, as shown in the examples <a href="https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/interesting-queries.md#transaction-outputs-for-specified-transaction-hash" rel="nofollow noreferrer">here</a>.</p>
<p>However, it is not as easy when I try to query token transactions. I used the multi_asset and ma_tx_out tables to identify which token was sent and in which transaction. I can see the address that received the token, but I cannot identify the address that sent the token when there are multiple input addresses.</p>
<p>For example, how can I know that (addr1q8h ... 8k5s6cnspc) sent the token and not the other input address in this <a href="https://cardanoscan.io/transaction/6c6dbbeff048eef367bdc5461ec797d031089ff02d141976a3c718822479d8bc" rel="nofollow noreferrer">transaction</a>? Is it actually possible to do that by only joining the tables?</p>

<transaction><cardano-db-sync><token><query>
How to query the address that sent a token from cardano-db-sync?
# How to query the address that sent a token from cardano-db-sync?

(Asked by: username_0 on 2022-07-05)

I'm trying to query the token transactions using the [schemas](https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/schema.md) of Cardano-db-sync. When querying ADA transactions, I can easily see the input and output addresses with the values sent by joining the tx, tx\_in, and tx\_out tables, as shown in the examples [here](https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/interesting-queries.md#transaction-outputs-for-specified-transaction-hash).

However, it is not as easy when I try to query token transactions. I used the multi\_asset and ma\_tx\_out tables to identify which token was sent and in which transaction. I can see the address that received the token, but I cannot identify the address that sent the token when there are multiple input addresses.

For example, how can I know that (addr1q8h ... 8k5s6cnspc) sent the token and not the other input address in this [transaction](https://cardanoscan.io/transaction/6c6dbbeff048eef367bdc5461ec797d031089ff02d141976a3c718822479d8bc)? Is it actually possible to do that by only joining the tables?

**Tags:** transaction, cardano-db-sync, token, query

---

## 1 answers

### Answer by username_1 on 2022-07-06. Score: 2

> For example, how can I know that (addr1q8h ... 8k5s6cnspc) sent the token and not the other input address in this transaction? Is it actually possible to do that by only joining the tables?

The multiple inputs of a transaction are not mapped individually to an output. All you can do is query the input UTxO to know assets associated with individual input (which is same for base currency, ADA) - you probably already have the latter part sorted, but just in case - sample example code used by [koios](https://api.koios.rest/#post-/tx_info) for complete transaction information can be found [here](https://github.com/cardano-community/guild-operators/blob/alpha/files/grest/rpc/transactions/tx_info.sql)

In the example you mention, it is easy to deduce since all the assets were present on single address. However, if you try to look at slightly more matured wallet transaction, this will likely complicate further as you'd be associating multiple inputs containing same asset - which is true also for base asset (ADA). The logic would be the same, consider inputs used to consume in desired output, and have the remainder spent to change address.


---

