<p>(I've opted for a short answer, aiming to shed enough initial light on it. Of course, this is my take on it and there is a lot more to be said about it.)</p>
<p>Smart contracts do not exist/live on-chain.<br />
They are units of software that exist/live off-chain and that generate transactions specific to the smart contract implementation.<br />
These transactions are executed on-chain and use EUTxOs as inputs.</p>
<p>Transactions are validated prior to execution. Smart contracts implement validators (scripts) to form part of the transaction validation routine. These validators provide validation specific to the smart contract that the transaction belongs to.</p>
<p>A smart contract implementation (currently written in Haskell) can share code between its off-chain implementation and the on-chain validators. The on-chain code is compiled separately into Plutus Core as part of the implementation.</p>
<p>The implementation of a smart contract includes validating the transactions it creates prior to sending them on-chain. This ensures that there can't be failed transactions that incur costs. A transaction may still fail when sent for execution if the input EUTxOs it was validated with are not available any more.</p>
<p>Smart contracts can be invoked programmatically, and there also is a PAB that exposes it through an API. Currently, it is up to the smart contract developer to make it available for use.<br />
However this is an area still very much under discussion. There are (early) plans to make smart contracts available as client browser apps interacting with e.g.Yoroi.</p>

CC BY-SA 4.0
2021-08-18T22:54:40.790Z
This answer provides me a lot of useful details. It isn't as structurally clear and terminologically clear enough to make me confident in my understanding though. You are dealing with a beginner though, so take that with a grain of salt :) Upvoted.
Matthew Capps
CC BY-SA 4.0
2021-08-19T15:11:34.587Z
Thanks @MatthewCapps! The aim of the answer was to be informative knowing it wasn't 'complete' so to speak. I wouldn't call myself an expert, but I think the most important is to share understanding.
vcwebco
CC BY-SA 4.0
2021-08-16T17:34:49.953Z
2021-08-16T17:34:49.953Z
vcwebco
<p><strong>BACKGROUND:</strong></p>
<p>A smart contract is the combination of off-chain and on-chain code that interact to form some desired behavior.</p>
<p>The on-chain smart contract code is called a script. The script can be compiled and the hash of that compiled code becomes the <em>unique</em> script address for that script.</p>
<p>EUTxOs are values that are owned by addresses on the blockchain. To spend EUTxOs at a script address, a transaction must be validated by the on-chain script.</p>
<p>If the hash of your compiled script doesn't match the script address, or the transaction is not validated by the script, you will not be able to spend the EUTxOs at the script address.</p>
<p><strong>ANSWER:</strong></p>
<blockquote>
<p>Where does a smart contract exist, in EUTxO?</p>
</blockquote>
<p>Smart contracts exist in combination on and off chain. The <strong>state</strong> of the smart contract is stored on EUTxOs on-chain, at script addresses. In order to modify the smart contract's state, you must spend EUTxOs and possibly generate new ones with new state. The rules that say how EUTxOs at a script address can be spent are the scripts themselves.</p>
<p>Hope that helps :)</p>

CC BY-SA 4.0
2021-08-18T22:57:55.177Z
'The on-chain smart contract code is called a script. That script code doesn't need to actually live on-chain though (explained below).'

These two sentences are confusing.

My inital takeaway is -- all of the smart contract's code is called a script, and is off-chain. The on-chain stamp that binds an EUTxO to it is the hash of the script-- called a 'script address.'

So, the on-chain component of a smart contract (script address) serves only to seal EUTxOs under a set off-chain rules (script).

But is some code (beyond Script Addr.) actually on chain? Do you see where I'm going wrong?
Matthew Capps
CC BY-SA 4.0
2021-08-19T00:07:58.170Z
I'll put it like this: If you can prove that the code you are having run by the nodes hashes to the script address, is there any need to save it on the chain? BUT, I just read some of the specs here (https://hydra.iohk.io/build/7244348/download/1/plutus.pdf) and it sound like the script is stored on the chain AFAICT. So I'll edit my original post. It's still a useful way of thinking of the on-chain scripts though!
Mitchell Turner
CC BY-SA 4.0
2021-08-16T19:17:10.040Z
2021-08-19T00:10:14.847Z
2021-08-19T00:10:14.847Z
Mitchell Turner
<p>In particular, I want to know whether the smart contract is somehow its own entity in the blockchain, or if a smart contract is just a property that EUTxOs may pick up.</p>
<p>EUTxOs are bound by smart contracts via their script addresses. But where actually is the script? To make it more practical-- how does a dapp dev actually get his smart contracts on-chain for others to use?</p>
<p>Some wild ideas passing through my head...</p>
<p><strong>a)</strong> you have to reference some off-chain script to cause your EUTxO to operate under it.</p>
<p><strong>b)</strong> you have to use a reference EUTxO, whose only purpose is to give a generic source for the smart contract's script,</p>
<p><strong>c)</strong> or else, maybe the script is deployed independently on-chain somehow (outside of an EUTxO).</p>
<p>I'm quite ignorant about how EUTxO works; so, a), b), and c) are just to help show you where you need to do surgery.</p>

<plutus><smart-contract>
Where does a smart contract exist, in EUTxO?
# Where does a smart contract exist, in EUTxO?

(Asked by: username_0 on 2021-08-16)

In particular, I want to know whether the smart contract is somehow its own entity in the blockchain, or if a smart contract is just a property that EUTxOs may pick up.

EUTxOs are bound by smart contracts via their script addresses. But where actually is the script? To make it more practical-- how does a dapp dev actually get his smart contracts on-chain for others to use?

Some wild ideas passing through my head...

**a)** you have to reference some off-chain script to cause your EUTxO to operate under it.

**b)** you have to use a reference EUTxO, whose only purpose is to give a generic source for the smart contract's script,

**c)** or else, maybe the script is deployed independently on-chain somehow (outside of an EUTxO).

I'm quite ignorant about how EUTxO works; so, a), b), and c) are just to help show you where you need to do surgery.

**Tags:** plutus, smart-contract

---

## 2 answers

### Answer by username_2 on 2021-08-16. Score: 9 | Accepted answer

**BACKGROUND:**

A smart contract is the combination of off-chain and on-chain code that interact to form some desired behavior.

The on-chain smart contract code is called a script. The script can be compiled and the hash of that compiled code becomes the *unique* script address for that script.

EUTxOs are values that are owned by addresses on the blockchain. To spend EUTxOs at a script address, a transaction must be validated by the on-chain script.

If the hash of your compiled script doesn't match the script address, or the transaction is not validated by the script, you will not be able to spend the EUTxOs at the script address.

**ANSWER:**

> Where does a smart contract exist, in EUTxO?

Smart contracts exist in combination on and off chain. The **state** of the smart contract is stored on EUTxOs on-chain, at script addresses. In order to modify the smart contract's state, you must spend EUTxOs and possibly generate new ones with new state. The rules that say how EUTxOs at a script address can be spent are the scripts themselves.

Hope that helps :)

> **Comments:**
> **username_0**: 'The on-chain smart contract code is called a script. That script code doesn't need to actually live on-chain though (explained below).'  These two sentences are confusing.  My inital takeaway is -- all of the smart contract's code is called a script, and is off-chain. The on-chain stamp that binds an EUTxO to it is the hash of the script-- called a 'script address.'  So, the on-chain component of a smart contract (script address) serves only to seal EUTxOs under a set off-chain rules (script).  But is some code (beyond Script Addr.) actually on chain? Do you see where I'm going wrong?  
> **username_2**: I'll put it like this: If you can prove that the code you are having run by the nodes hashes to the script address, is there any need to save it on the chain? BUT, I just read some of the specs here (https://hydra.iohk.io/build/7244348/download/1/plutus.pdf) and it sound like the script is stored on the chain AFAICT. So I'll edit my original post. It's still a useful way of thinking of the on-chain scripts though!  

---

### Answer by username_1 on 2021-08-16. Score: 6

(I've opted for a short answer, aiming to shed enough initial light on it. Of course, this is my take on it and there is a lot more to be said about it.)

Smart contracts do not exist/live on-chain.  
They are units of software that exist/live off-chain and that generate transactions specific to the smart contract implementation.  
These transactions are executed on-chain and use EUTxOs as inputs.

Transactions are validated prior to execution. Smart contracts implement validators (scripts) to form part of the transaction validation routine. These validators provide validation specific to the smart contract that the transaction belongs to.

A smart contract implementation (currently written in Haskell) can share code between its off-chain implementation and the on-chain validators. The on-chain code is compiled separately into Plutus Core as part of the implementation.

The implementation of a smart contract includes validating the transactions it creates prior to sending them on-chain. This ensures that there can't be failed transactions that incur costs. A transaction may still fail when sent for execution if the input EUTxOs it was validated with are not available any more.

Smart contracts can be invoked programmatically, and there also is a PAB that exposes it through an API. Currently, it is up to the smart contract developer to make it available for use.  
However this is an area still very much under discussion. There are (early) plans to make smart contracts available as client browser apps interacting with e.g.Yoroi.

> **Comments:**
> **username_0**: This answer provides me a lot of useful details. It isn't as structurally clear and terminologically clear enough to make me confident in my understanding though. You are dealing with a beginner though, so take that with a grain of salt :) Upvoted.  
> **username_1**: Thanks @MatthewCapps! The aim of the answer was to be informative knowing it wasn't 'complete' so to speak. I wouldn't call myself an expert, but I think the most important is to share understanding.  

---

