user1231: As I understand, a smart contract in Cardano contains on-chain code and off-chain code.

On-chain code is executed by cardano nodes in order to validate transaction.
Off-chain code builds a transaction in the user wallet then submit it to the blockchain.

On-chain code is stored in the blockchain, but what about off-chain code if this is executed on user wallet. Where is this code stored?
I guess is in the blockchain too, but how does the user wallet get it?

user1130: 
I guess [the off-chain code] is in the blockchain too[?]

No. Actually. They mean it when they call it "off-chain" :).
Background:
Generally speaking, you want to minimize the amount of code you put on-chain because that code is expensive. For Plutus smart contracts, the role of on-chain code is simply to look at a transaction and say "yes" or "no".
There are two uses for the off-chain code:

Compile and submit the on-chain scripts
Create transactions that will be validated by the on-chain scripts

But as I mention in this other question's answer, there is nothing keeping someone from writing their own off-chain code to interact with the on-chain script. This is important for a smart-contract writer to understand when thinking about the security of the on-chain validation.
Answer:

Where is stored off-chain code?

There is nothing binding the on-chain code to a singular off-chain code. So there is no correct answer.

How does the user wallet get it?

From what I understand, there will be options. It could be stored in a repo by the SC writer where you could download it, or perhaps hosted on a website where your wallet can access it (similar to how Metamask works on Uniswap or other Ethereum sites), or you could write it yourself in an attempt to exploit the contract.
As a SC creator, it will be your responsibility to make your off-chain code available to consumers so they can interact with your contract in your intended way.

1231: <p>As I understand, a smart contract in Cardano contains on-chain code and off-chain code.</p>
<ul>
<li>On-chain code is executed by cardano nodes in order to validate transaction.</li>
<li>Off-chain code builds a transaction in the user wallet then submit it to the blockchain.</li>
</ul>
<p>On-chain code is stored in the blockchain, but what about off-chain code if this is executed on user wallet. Where is this code stored?</p>
<p>I guess is in the blockchain too, but how does the user wallet get it?</p>
 1130: <blockquote>
<p>I guess [the off-chain code] is in the blockchain too[?]</p>
</blockquote>
<p>No. Actually. They mean it when they call it &quot;off-chain&quot; :).</p>
<p><strong>Background:</strong></p>
<p>Generally speaking, you want to minimize the amount of code you put on-chain because that code is expensive. For Plutus smart contracts, the role of on-chain code is simply to look at a transaction and say &quot;yes&quot; or &quot;no&quot;.</p>
<p>There are two uses for the off-chain code:</p>
<ol>
<li>Compile and submit the on-chain scripts</li>
<li>Create transactions that will be validated by the on-chain scripts</li>
</ol>
<p>But as I mention in this <a href="https://cardano.stackexchange.com/a/914/1130">other question's answer</a>, there is nothing keeping someone from writing their own off-chain code to interact with the on-chain script. This is important for a smart-contract writer to understand when thinking about the security of the on-chain validation.</p>
<p><strong>Answer:</strong></p>
<blockquote>
<p>Where is stored off-chain code?</p>
</blockquote>
<p>There is nothing binding the on-chain code to a singular off-chain code. So there is no correct answer.</p>
<blockquote>
<p>How does the user wallet get it?</p>
</blockquote>
<p>From what I understand, there will be options. It could be stored in a repo by the SC writer where you could download it, or perhaps hosted on a website where your wallet can access it (similar to how Metamask works on Uniswap or other Ethereum sites), or you could write it yourself in an attempt to exploit the contract.</p>
<p>As a SC creator, it will be your responsibility to make your off-chain code available to consumers so they can interact with your contract in your intended way.</p>
