3

The person initiating a transaction to start a transaction provides one or more UTxO from their wallet, but where does the script UTxO come from? Does the initiating participant provide a script address for the contract in their wallet and the PAB forges a new UTxO for the transaction? How exactly does that work?

2 Answers 2

1

When we think about someone interacting with a script they are either sending a UTXO to the script or spending a UTXO that currently resides at at the script.

I will try to clarify what I think you're not understanding using a DEX as an example: I (the buyer) can create an order on MuesliSwap saying I want to buy a certain token for X ADA by sending a UTXO (that is usually "from my wallet") containing specific data to the MuesliSwap script. Now, that UTXO is locked at the script address. Another user (the seller) can then spend this UTXO that is at the MuesliSwap script address if their transaction meets the requirements that the MuesliSwap contract code enforces, which in this case would be that the buyer receives the token (the seller includes a UTXO containing the token as another input in addition to the UTXO at the script) and sending the seller the X ADA that is locked in the UTXO the buyer sent to the script.

Multiple of these "buyer order UTXOs" can reside at the script address and would impose different requirements on the script validation depending on the data inside them (buyer wants token XYZ for 123 ADA). A seller can choose which UTXO at the script address they wish to spend to in order to complete a trade.

This example shows that sometimes you are spending a UTXO from your wallet to lock it at a script, and other times you are spending a UTXO that someone has sent to the script instead of one from your wallet, depending on the context and what you are trying to do. So when you ask "where does the script UTXO from?", in the example above it would be the UTXO the buyer sent to the script, if I am understanding your question correctly.

2
  • As far as I can make out, when the developer of the contract adds the script to the blockchain, it will be via a transaction on the blockchain that outputs the UTxO that has the script address. That UTxO output from the initial transaction is then available as an input in any other transaction that asks to consume it and validates. That validated transaction then, in turn, outputs a new UTxO as the continuation of the script since the initial UTxO is spent/consumed by the validated transaction. Is that the workflow?
    – nyk
    Jan 20 at 14:23
  • I updated my answer a little. In essence, yes - but there it isn't really a notion of the developer "adding the script to the blockchain", more that because they would be the first to know the script address they could be the first to send a UTXO to it. In my example, the buyer's UTXO could be the first UTXO sent to the script address, they just need the script's Plutus code and the script address, so it is not true that the developer would always create the first UTXO at the script. There isn't really a notion of script deployment.
    – hrpr
    Jan 20 at 15:19
0

Think of the script address as a mailbox with a lock. Anyone can view and deposit assets into the mailbox (just like any other address on chain). Unlike any other address however, unlocking the funds requires more than just a private key signature.

Rather, it requires that any transaction using a UTXO residing at the script address as an input evaluates to the same script hash specified by the script address. In other words, the only way to spend from a script address is to supply proof (in the form of matching script hashes) that the transaction logic is identical to what was outlined by the creator of the script address.

When spending from a script address, you would reference the desired UTXO input via its Tx-id, just like any other UTXO input.

2
  • I understand that part of the transaction and appreciate your response. Unfortunately, my question is badly worded. What I'm trying to understand is the transaction that outputs the initial EUTxO. By definition, the UTxO must be the output of a transaction, and so the question is what is that transaction and who/what generates that transaction to produce the EUTxO with that script address?
    – nyk
    Jan 19 at 19:20
  • If I send you ADA. I create a transaction that consumes one or more UTXOs under my control, and outputs one or more UTXO's to an address that you control. You can then spend your new UTXO's with your private keys. The first half is the same for scripts addresses: anyone can send assets to a script address. However, in order to spend from the script address, they must construct their transaction such that their script hash evaluates to the same hash as the one defined by the script address. This ensures their transaction behaves in exactly the way intended by the script address's author.
    – zhekson
    Jan 20 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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