When starting with Pact, you’ll often create single modules that contain the full functionality of your smart contract.

This raises an important question...

Why aren’t modules called smart contracts?

The reason for this becomes clear once you begin creating more complicated smart contracts. These smart contracts will often contain many modules that work together to create your application. The goal of each module should be to create a focused set of functionality and clear organization within your files.

While one module can make one smart contract, many modules can also make one smart contract. For that reason, we refer to the logic within a Pact file as a module.

The entire module is written within these parentheses. The top level code, like keysets, are defined outside of these parentheses.

The basic idea of modules is simple, but the structure of the code and the actual logic within the module can get pretty complicated. For that reason, it’s helpful to start by focusing on the basic syntax and structure of existing modules.

While you may not fully understand each line of code quite yet, there are a few important things to note here.

First, schemas and tables are defined inside of modules, but tables are created outside of modules. Table and schema definitions include built in functions including defschema, deftable, and create-table. You’ll learn more about each of these functions in the Pact Schemas and Tables tutorial.

Next, there are some new Pact built in functions that you may have not seen before.

Other modules include the same basic framework as those included in these simple smart contracts. Take some time now to explore each of the other Smart Contract examples to get more familiar with how they work.

Example Modules

International Payment

Verification

Accounts

Focus on understanding the structure of each module. Gain some familiarity with the different techniques used to create each smart contract.

In this tutorial you were introduced to modules, one of the core features of the Pact Programming Language. You learned what modules are, why they’re important, and went over a few examples.

The goal for this tutorial wasn’t to help you learn all of the code that can possibly go into creating a module. That’s what most of the entire Pact programming language is built to accomplish. You’ll learn much more about this in later tutorials.

For now, the important takeaway is to understand what a module is, as well as to recognize the key elements that belong inside and outside of Pact modules.

Take some time now to continue exploring the examples provided in the Pact Online Editor. When you’re ready, you can learn more about the Pact programming language in our next tutorial.