8

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?

7

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:

  1. Compile and submit the on-chain scripts
  2. 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.

2
  • 1
    Also, I imagine a central repository similar to what we have for tokens metadata will be ran by the Cardano Foundation. Aug 1 at 11:34
  • This. I imagine at some point there could be a dApp browser of sorts. As we’ve seen with the Plutus Playground, the endpoints interface can be used auto-generate a UI. This could help lower the barrier to entry for dApp writers so they don’t need to build a UI themselves. If you can get your SC onto the registry then anyone can find it and use it. Aug 1 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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