Version: 0.31.0


In some cases it's necessary to interrupt the flow of execution and fail the contract. This is where the failwith function comes in.

The failwith function#

The failwith function raises an error that cannot be caught, and terminates the contract.

let main = (p: unit, s: unit): unit => {
if (true) {
failwith("This contract always fails");

The call to failwith should be annotated with a type as the type-checker cannot infer the correct type yet.


Assertions can be used to ensure a certain condition is met when running a contract. assert is used to check if a boolean condition is true and assert_some is used to check if an option value is not None. When a condition is not met, the contract will stop executing and display an error.

let main = (p: bool, s: unit): [list<operation>, unit] => {
let u: unit = assert(p);
return [list([]) as list<operation>, s];
let some = (o: option<unit>): unit => {

You can use assert_with_error or assert_some_with_error to use a custom error message

let main2 = (p: bool, s: unit): [list<operation>, unit] => {
let u: unit = assert_with_error (p, "my custom error message");
return [list([]) as list<operation>, s];