3

We are trying to figure out how to identify the sender (source address) of a given transaction retrieved using cardano-wallet.

Here is an example datastructure from the api. Be aware the field values are randomized (not real):

{
  inserted_at: {
    height: { quantity: 4263, unit: "block" },
    time: "2021-11-21T18:00:39Z",
    epoch_number: 190,
    absolute_slot_number: 4323,
    slot_number: 132423,
  },
  status: "in_ledger",
  withdrawals: [],
  amount: { quantity: 2000000, unit: "lovelace" },
  inputs: [
    {
      id: "80b4ab2773da9bccdb62d8bbf22f339bf041f0ff082f34acc6614f6a759e58e",
      index: 0,
    },
  ],
  direction: "incoming",
  fee: { quantity: 0, unit: "lovelace" },
  outputs: [
    {
      amount: { quantity: 2000000, unit: "lovelace" },
      address:
        "addr_test1qzwtzc4vrase42ytaj8nqam6z4322x5dx08gj2gxtjqy05wl5feqsw9lgy9askcyzjemw4d8x94n25nq204j6kqfpmhsn64us7",
      assets: [],
    },
    {
      amount: { quantity: 56, unit: "lovelace" },
      address: "addr_test1vqd00tpc537seq9hy64pupcu7s88x5w9jdln4lqyfees3swgmk",
      assets: [],
    },
  ],
  metadata: None,
  depth: { quantity: 370, unit: "block" },
  id: "d6c29eb3a8865b1e79d5cf2beb4d04b6685145a2c73d910d70e8f80080384",
  deposit: { quantity: 0, unit: "lovelace" },
  collateral: [],
  mint: [],
};

Now, the source address is listed in one of the outputs, since the transaction must send the remainder of the balance to it. However, this isn't a great way to identify the source address because it might not be there if there is no remainder, or there may be 3 or more outputs.

I expected the inputs to contain the address, but it just has an id.

I see no other mentions of the source address. How does one figure out who sent a transaction?

3
  • Not sure what you mean by the source of a TX, tx's in cardano consume a bunch of utxo's and create a bunch of utxo's, anyone with a wallet can create a TX and will need to sign it, so if the creator is what you mean by source, then the source is your wallet (or the wallet that created the tx)
    – Calin
    Nov 23, 2021 at 11:32
  • All of that is accurate. So, based on the above data struct, can you tell me what wallet created the transaction?
    – melchoir55
    Nov 23, 2021 at 18:15
  • Not really, a wallet can verify that it signed a transaction, so in a way you can have a wallet claim the tx.
    – Calin
    Nov 24, 2021 at 8:44

5 Answers 5

1

You cannot find the sender address using cardano-wallet. You will need to install cardano-db-sync for that and query it, or you will have to use an external API (like blockfrost.io) and make a call to the endpoint documented here: https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1{hash}~1utxos/get

0

A transaction consumes UTXOs not addresses, therefore you can see the 80b4ab2773da9bccdb62d8bbf22f339bf041f0ff082f34acc6614f6a759e58e#0 which is the UTXO being consumed.

To find out the originating address, you might need to list the transaction that created this UTXO.

I do not think cardano-wallet supports finding the wallet of a given address, so you would need to look through all the wallets to find your address.

1
  • Does this mean I would have to iterate through every wallet in existence looking for that utxo id in the wallet's transaction history? I don't think even that would work as the cardano-wallet api does not provide this kind of information in the wallet endpoint. There must be a way to figure out the sender, no? Wallets like daedalus show the sender. Is cardano-wallet just a red herring project which is unused?
    – melchoir55
    Nov 23, 2021 at 19:36
0

You can query the input transaction hash, in your case 80b4ab2773da9bccdb62d8bbf22f339bf041f0ff082f34acc6614f6a759e58e using a block explorer like cardanoscan, or from your own running node using cardano-db-sync

For example, when I search the above Tx Hash in cardanoscan, I get: https://testnet.cardanoscan.io/address/80b4ab2773da9bccdb62d8bbf22f339bf041f0ff082f34acc6614f6a759e58e

It seems like an unused address, but you mentioned the values were randomized. Try querying using the real TX hash that you are interested in. You should then be able to gather the info you need.

1
  • This is a good approach, but requires db-sync. I was trying to figure out a way using cardano-wallet.
    – melchoir55
    Dec 24, 2021 at 5:24
0

You all are way over complicating this.. It's as easy as:

def get_return_address_from_utxo(utxo):
try:
    r = requests.get(f"https://cardanoscan.io/transaction/{utxo}")

    content = r.content.decode("utf-8").split(
        'FROM ADDRESSES (INPUTS)</span></div></div><div class=mt-4><div class="d-flex flex-row '
        'justify-content-between px-3"><div><strong>Address</strong></div><div><strong>Amount</strong></div></div><hr class=darkHR><div data-simplebar><div class="d-flex flex-row justify-content-between px-2"><div class=addressField><div class="row align-items-center"><div class=col-auto>')
    sub = content[1].split("span")
    address = sub[0]
    address = address.replace("<a href=/address/", "").replace("><", "")
    return address
except requests.exceptions.RequestException as e:
    return ''
except IndexError as e:
    return ''
4
  • This is a pretty cool solution. Unfortunately, it relies on third party data (cardanoscan) which introduces a vector for attack. If it were a fun website providing data this would be fine but as a payment processor this isn't an acceptable security tradeoff.
    – melchoir55
    Dec 27, 2021 at 17:24
  • Something similar could just as easily be built using explorer.cardano.org which is IOHK and not third party..
    – Tygar Pool
    Dec 27, 2021 at 18:55
  • iohk is a third party. But, maybe trustworthy depending on what you're building for.
    – melchoir55
    Dec 27, 2021 at 20:14
  • 1
    Also, parsing HTML content that can change at any time is pretty fragile. Mar 22 at 20:18
0

You can use db-sync. I wrote an article about how to do it on Medium

How to identify who sent a Cardano transaction using db-sync

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 1 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.