Functions
Functions work as you would expect in TypeScript. For example:
function addOneAndDouble(x: Field): Field { return x.add(1).mul(2);}Here we take the input x, add 1 to the Field value, multiply it by two and return the new Field.
Try it out
Let’s first call the addOneAndDouble function with our defined Field x and call the result y:
const y = addOneAndDouble(x);Now check if our y field is equal to the value of 4:
const isEqual = y.equals(4);Log the variables y and isEqual:
Provable.log("y is:", y);Provable.log("y is equal to 4:", isEqual);Now build and run the script in the terminal:
npm run build && node build/src/index.jsThis will log the following:
y is: 4y is equal to 4: trueFiles
Preparing Environment
- Installing dependencies