I was looking for a simple way to get exact TxOut on on-chain code to validate if funds are to be unlocked to correct wallet address. While looking in plutus haddoc I have found this function:

{-# INLINABLE findOwnInput #-}
-- | Find the input currently being validated.
findOwnInput :: ScriptContext -> Maybe TxInInfo
findOwnInput ScriptContext{scriptContextTxInfo=TxInfo{txInfoInputs}, scriptContextPurpose=Spending txOutRef} =
    find (\TxInInfo{txInInfoOutRef} -> txInInfoOutRef == txOutRef) txInfoInputs
findOwnInput _ = Nothing

This function returns:

-- | An input of a pending transaction.
data TxInInfo = TxInInfo
    { txInInfoOutRef   :: TxOutRef
    , txInInfoResolved :: TxOut
    } deriving stock (Generic, Haskell.Show, Haskell.Eq)

And here is where most of my confusion comes from - getOwnInput returns TxInInfo which has TxOut. All I see is TxIn is TxOut. This makes it really unclear to me exactly which part of locking or unlocking transaction UTXO getOwnInput function returns.

Lets say that I have 10 Ada in wallet A and I'm creating locking transaction TX1 of 2 Ada to SC1. The way I see it TX1 should look like this:

  1. UTXO1 of 10 ADA is created by taking all the funds from wallet A.
  2. UTXO2 of 10 ADA - 2 ADA - fees1 is created and is sent back to wallet A.
  3. UTXO3 of 2 ADA is created and sent to SC1.

Lets say that now I'm trying to unlock 2 ADA from SC1 back to wallet A by creating TX2:

  1. UTXO4 10 ADA - 2 ADA - fees1 are taken from wallet A to pay for fees2
  2. UTXO5 2 ADA is being taken from SC1
  3. UTXO6 2 ADA are sent to wallet A
  4. UTXO7 10 ADA - 2 ADA - fees1 - fees2 are sent back to wallet A

Main question

So my main question is. Which of these UTXOs does the function getOwnInput return as a txInInfoResolved when TX2 is created?

Bonus question

When TX2 is created, from Plutus validator point of view, which of UTXOs are TxOut and which are TxIn?

  • My guess would be that answer to main question is UTXO3, because on this tx pubKeyOutput returns Nothing. I suppose it is because UTXO3 goes into smartcontract which doesn't have PubKeyHash but has ValidatorHash instead.
    – KugisMugis
    Jan 27, 2022 at 10:16

1 Answer 1


Calling findOwnInput in a validator returns the value contained in the Script-UTxO that is currently being validated. In your example above it is the one with 2 Ada in it.

Your example above is, however, not correctly formulated: UTXO4 is in fact UTXO2 and UTXO5 is UTXO3, also UTXO7 and UTXO4 are not necessary.

Your Answer

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

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