5

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?

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...)

3 Answers 3

5

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).

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.

2

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

Where is stored off-chain code?

On-chain and off-chain for Plutus SCs

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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