Search code examples
pact-lang

Typing Variables in Functions


I was attempting a basic hello world smart contract in Pact. While being able to complete the contract I received a warning. It didn't stop my contract from running but did concern me.

In future lengthier contracts will I have to place the type next to the parameter in a function?

My example (Sample Picture):(defun hello (name)

The above throws a warning but the following does not (No Warning):defun hello (name:string)

Is it best practice to include the type? (name:string)


Solution

  • Yes, Pact encourages you to strongly type the input parameters that touch the database. However, the types of the input parameters that are specified in the schema can be detected and do not need to be written out in the function definition. On Pact online editor, the contract is typechecked in default. If you’re writing Pact in a text editor (currently supported in Atom), you can add (typecheck ’moduleName) in the repl file to see the warnings.