I would like to create a smartcontract which makes sure that only the same person who made specific locking transaction can unlock that same specific transaction or to put it into simpler terms if Bob locks his Ada then smartcontract must ensure that only Bob can unlock his locked Ada.

I think in TxInfo one of the txInfoInputs UTxO should contain information about locking transaction. But from data definition of txInfoInputs :: [TxInInfo] field:

data TxInInfo = TxInInfo
    { txInInfoOutRef   :: TxOutRef
    , txInInfoResolved :: TxOut
    } deiriving stock (Generic, Haskell.Show, Haskell.Eq)

I can't tell how exactly could I get public key hash of source address or something else which could give me information for validation if unlocking transaction is being made by the same person who made locking transaction.

Another way I can think of is to add sender address into Datum but I can't think of a way how to ensure secure Datum creation process so that for example when Bob is creating transaction to luck funds in smartcontract Alices address as a receiver doesn't appear in Datum

So is it even possible, to create such smartcontract which would take information of locking transaction and by using that information validate if smartcontract funds can be unlocked?

1 Answer 1


In TxOut you have a field txOutAddress that you can use for this:

data TxOut = TxOut {
  txOutAddress   :: Address,
  txOutValue     :: Value,
  txOutDatumHash :: Maybe DatumHash

Use it to extract the pubkeyhash:

pkh = toPubKeyHash $ txOutAddress txOut

And then in the smart contract check if the transaction is signed by it:

txSignedBy (scriptContextTxInfo ctx) pkh

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.