<p>Here are two threads that discuss the relationship between on-chain and off-chain code:</p>
<p><a href="https://cardano.stackexchange.com/q/2274/1130">Where is stored off-chain code?</a></p>
<p><a href="https://cardano.stackexchange.com/q/913/1130">On-chain and off-chain for Plutus SCs</a></p>
<blockquote>
<p>What does &quot;off-chain code lives in the wallet&quot; mean?</p>
</blockquote>
<p>Off-chain code uses the context in your wallet, e.g. UTxOs and addresses, to construct a transaction that will be validated by the on-chain code and return any change back to your wallet.</p>

CC BY-SA 4.0
2022-01-24T18:53:30.100Z
2022-01-24T18:53:30.100Z
Mitchell Turner
<p>I think that phrase can be a little misleading. Off-chain code will live anywhere close to where your end users will interact with your DApp. It is responsible for composing the correct transactions, so it does need to be aware of the contract specifications.</p>
<p>However, it does not need to be an actual wallet that runs the code to compose the transaction in the first place.</p>
<p>You can, for example, have a website or an app that is connected to your own backend server and when 1) a user interacts with it, 2) the server generates a valid transaction on-demand (incl. any scripts), 3) the transaction is then passed to the user's wallet only for signing (eg a browser extension) and 4) submitted to the network (either by the server or the wallet).</p>

CC BY-SA 4.0
2022-01-24T18:14:30.700Z
2022-01-24T18:14:30.700Z
sean
<p>In the same question that you linked, I mentioned:</p>
<blockquote>
<p>&quot;The actual logic must therefore be performed in a local environment.&quot;</p>
</blockquote>
<p>This is what it means to run off-chain code. Think about it this way: the on-chain part of a smart contract is a <em>logical proof</em> that a transaction was performed in a <em>certain way</em>, but the actual <em>doing</em> of that way is performed in your wallet (locally). It does not have to be in your wallet per say, but it can be if that is how your local environment is set up.</p>
<p>Even simpler: your computer does logic and generates a proof --&gt; blockchain verifies said proof and if ok, validates the transaction.</p>

CC BY-SA 4.0
2022-01-24T13:08:04.693Z
2022-01-24T13:08:04.693Z
zhekson
<p>That terminology was used in PPP3 lectures, but what does it mean?</p>
<p>The spending transaction should follow rules of the smart contract as was answered here <a href="https://cardano.stackexchange.com/questions/6767/can-blockchain-viewers-read-the-source-code-of-a-smart-contract-if-they-know-its">Can blockchain viewers read the source code of a smart contract if they know its address?</a></p>
<p>The spender by default doesn't know the rules to form the spending transaction. Or his wallet can read the off-chain code of our smart contract somehow? The wallet actually has the whole copy of the blockchain and our smart contract inside also.</p>
<p>Because only the verification script (on-chain code) is hashed to provide the address (but probably we submit to the blockchain only on-chain code, I am not sure...)</p>

<plutus-pioneer-program>
What does "off-chain code lives in the wallet" mean?
# What does "off-chain code lives in the wallet" mean?

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

That terminology was used in PPP3 lectures, but what does it mean?

The spending transaction should follow rules of the smart contract as was answered here [Can blockchain viewers read the source code of a smart contract if they know its address?](https://cardano.stackexchange.com/questions/6767/can-blockchain-viewers-read-the-source-code-of-a-smart-contract-if-they-know-its)

The spender by default doesn't know the rules to form the spending transaction. Or his wallet can read the off-chain code of our smart contract somehow? The wallet actually has the whole copy of the blockchain and our smart contract inside also.

Because only the verification script (on-chain code) is hashed to provide the address (but probably we submit to the blockchain only on-chain code, I am not sure...)

**Tags:** plutus-pioneer-program

---

## 3 answers

### Answer by username_2 on 2022-01-24. Score: 5 | Accepted answer

I think that phrase can be a little misleading. Off-chain code will live anywhere close to where your end users will interact with your DApp. It is responsible for composing the correct transactions, so it does need to be aware of the contract specifications.

However, it does not need to be an actual wallet that runs the code to compose the transaction in the first place.

You can, for example, have a website or an app that is connected to your own backend server and when 1) a user interacts with it, 2) the server generates a valid transaction on-demand (incl. any scripts), 3) the transaction is then passed to the user's wallet only for signing (eg a browser extension) and 4) submitted to the network (either by the server or the wallet).


---

### Answer by username_3 on 2022-01-24. Score: 5

In the same question that you linked, I mentioned:

> "The actual logic must therefore be performed in a local environment."

This is what it means to run off-chain code. Think about it this way: the on-chain part of a smart contract is a *logical proof* that a transaction was performed in a *certain way*, but the actual *doing* of that way is performed in your wallet (locally). It does not have to be in your wallet per say, but it can be if that is how your local environment is set up.

Even simpler: your computer does logic and generates a proof --> blockchain verifies said proof and if ok, validates the transaction.


---

### Answer by username_1 on 2022-01-24. Score: 2

Here are two threads that discuss the relationship between on-chain and off-chain code:

[Where is stored off-chain code?](https://cardano.stackexchange.com/q/2274/1130)

[On-chain and off-chain for Plutus SCs](https://cardano.stackexchange.com/q/913/1130)

> What does "off-chain code lives in the wallet" mean?

Off-chain code uses the context in your wallet, e.g. UTxOs and addresses, to construct a transaction that will be validated by the on-chain code and return any change back to your wallet.


---

