I am writing a public function that only owner of the contract can call. It is a funciton that changes a state variable in a smart conract.
(define-public (changeRatio (newRatio uint))
(begin
(asserts! (is-eq tx-sender (var-get contract-owner)) ERR-NOT-AUTHORIZED)
(var-set ratio newRatio)
)
)
and I get
error: detected two execution paths, returning two different expression types (got '(response UnknownType uint)' and 'bool')
what am I doing wrong here?
Public functions in Clarity have to return a response type at the end. See the Clarity book for more info on this: https://book.clarity-lang.org/ch05-01-public-functions.html
To solve your particular error, you could wrap your
var-setin anokresponse type like this:(ok (var-set ratio newRatio))Note that this will only work if your
ERR-NOT-AUTHORIZEDis anerrand not just auint, sinceerrandokare both response types.