0

In my smart contract, I want to check whether a boolean value is true, if not the smart contract should abort or throw an error like

(begin
   (require-true value)
   ...continue
)

How can I do that?

Lee
  • 29,398
  • 28
  • 117
  • 170
friedger
  • 645
  • 7
  • 21
  • For exiting early and returning an error there is `asserts!` (https://docs.blockstack.org/references/language-functions#asserts) – friedger Nov 21 '20 at 07:07

2 Answers2

0

You can use unwrap-panic in a function, e.g.

(define-private (require-true (value bool))
  (unwrap-panic (if value (some true) none))
)
friedger
  • 645
  • 7
  • 21
0

asserts! will return true and continue the execution only if the boolean expression it evaluates is true. If not it will return the thrown-value and exit the current control flow.

Signature is: (asserts! boolean-expression thrown-value)

Example that will return true and continue execution:

(asserts! (is-eq 1 1) (err 1))