Can we deploy predicates on-chain or do we need to load each time we run it, like a script with an address and returning boolean?
The following article describes predicates really well: The Power of Predicates: A Purpose-Built Mechanism for Transaction Authorization | by Ryan Sproule | Blockchain Capital Blog | Jan, 2023 | Medium
To quote the article:
“Unlike contract code, predicate code is never “deployed” to the chain. To create a predicate, someone simply writes the code for the predicate and then uses a compiler to generate a code hash, there is no interaction with the chain. Since the hash is both deterministic and collision-resistant, the coins locked in this address can only ever be spent if the predicate conditions are met. To spend a predicate, someone would provide the predicate bytecode (which must match the hash/address that the coins are behind) and a transaction that has the predicate resolve to true.”
thanks for your reply, that is a very good answer.
btw, I agree with your understanding and I personally feel predicate in sway is very similar to bitcoinscript.
However, in sway programming language github.io, there is a paragraph:
A Sway program itself has a type: it is either a contract, a predicate, a script, or a library. The first three of these things are all deployable to the blockchain. A library is simply a project designed for code reuse and is never directly deployed to the chain.
seems on the sway book, it mentions predicate is deployable.
Oh yes thank you for pointing this out. Indeed, this is a misleading sentence. We should change it, so I opened this issue: Clarify how different program types are used · Issue #3908 · FuelLabs/sway · GitHub
also checkout here:
i am a bit confused here lol
Yeah fixing this now, predicates can’t be deployed, only supplied as inputs. PR for correction is open here
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.