<p>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.</p>
<p>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 &quot;from my wallet&quot;) 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.</p>
<p>Multiple of these &quot;buyer order UTXOs&quot; 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.</p>
<p>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 &quot;where does the script UTXO from?&quot;, in the example above it would be the UTXO the buyer sent to the script, if I am understanding your question correctly.</p>

CC BY-SA 4.0
2022-01-20T14:23:42.587Z
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
CC BY-SA 4.0
2022-01-20T15:19:47.990Z
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
CC BY-SA 4.0
2022-01-20T01:49:51.237Z
2022-01-20T15:15:26.867Z
2022-01-20T15:15:26.867Z
hrpr
<p>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.</p>
<p>Rather, it requires that <strong>any transaction using a UTXO residing at the script address <em>as an input</em> evaluates to the same script hash specified by the script address</strong>. 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.</p>
<p>When spending from a script address, you would reference the desired UTXO input via its Tx-id, just like any other UTXO input.</p>

CC BY-SA 4.0
2022-01-19T19:20:11.867Z
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
CC BY-SA 4.0
2022-01-20T03:12:10.897Z
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
CC BY-SA 4.0
2022-01-18T16:29:50.800Z
2022-01-18T16:29:50.800Z
zhekson
<p>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?</p>

<plutus-pioneer-program>
Payment eUTxO input come from wallets, but what contains/forges the script eUTx0 inputs?
# Payment eUTxO input come from wallets, but what contains/forges the script eUTx0 inputs?

(Asked by: username_0 on 2022-01-18)

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?

**Tags:** plutus-pioneer-program

---

## 2 answers

### Answer by username_1 on 2022-01-20. Score: 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.

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.  

---

### Answer by username_2 on 2022-01-18. Score: 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.

> **Comments:**
> **username_0**: 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?  
> **username_2**: 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.  

---

