I understand its a program that returns true or false, but I’m still not clear how its used or why its interesting.
A predicate is a pure (does not access state) contract script that simply returns a boolean (true or false). UTXOs can be locked behind a predicate so they can only be spent whenever the conditions defined in the predicate are met. This leads to an interesting UX opportunity where users can set a transaction to execute only under certain conditions, and then once the predicate is met, their transaction can automatically execute. Also, predicates can be pruned when they are destroyed, so they do not contribute to state bloat.
Check out the docs for predicates (updates coming soon to improve these): Predicates - The Sway Programming Language
Predicates are pure functions evaluating to either True or False. They are stateless, and can neither read nor write to any contract state. Check out the docs here.
In Fuel, coins can be sent to an address representing a particular predicate. Without diving too deep, the address (predicate/bytecode root) is a hash of the predicate’s bytecode. The specifics of this are found here. These coin UTXOs are then spendable not on the action of a valid signature, but if a transaction’s supplied predicate has a root that matches their owner and evaluates to True.
One of example of using predicates is with Fuel’s OTC swap predicate application.
Here, the predicates act as Over-the-Counter orders that anyone can fill. The order maker transfers coin to the predicate root which can be unlocked and spendable by any transaction that has an output that satisfies the conditions of the order (making the predicate return True). The spending transaction must transfer the requested/asked amount of a specified token to the specified receiver (possibly the order maker). These requirements are hardcoded into the predicate so that the bytecode root commits to them.
Something to note about this. Orders cannot be partially filled as the order taker must pay the entire ask amount to satisfy the predicate’s specific conditions.
The OTC swap application is amazing for simple trades and this kind of technology is great for atomic swaps. In some cases, predicates can eliminate the need to deploy a smart contract which is largely expensive.
The beauty of predicates in Fuel is that you can define the set of conditions that permit coins to be spent by anyone. This is in comparison to the single cryptographic condition of spending coins through the validation of a specified wallet.
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.