# FRAME Pallet

substrate\_ *has a long list of pre-packages pallets, but you can also build your own or modify one built by the substrate*\_ team.

## Pallet Structure

A pallet is composed of a few building blocks. These are:

1. [Imports](#imports-and-dependencies)
2. [Declaration of Pallet Type](#declaration-of-the-pallet-type)
3. [Runtime Configuration Trait](#runtime-configuration-trait)
4. [Runtime Storage](#runtime-storage)
5. [Runtime Events](#runtime-events)
6. [Hooks](#hooks)
7. [Extrinsics (Dispatchable Calls)](#dispatchable-call)

### No Std

The first line of code, always. It tells the rust compiler not to use Rust's standard library except when explicitly told so.

{% hint style="warning" %}
Substrate runtimes are compiled to WASM and a regular native binary so you **do not have access to rust's standard library**.&#x20;

This means simple things like printing to the command line using `println!` will not compile.&#x20;

[Learn more here](https://substrate.recipes/runtime-printing.html#printing-from-the-runtime).
{% endhint %}

### [Imports](https://app.gitbook.com/o/VlWTV0GJXmoHRKrDvk52/s/3UKO6MPPEQpqMJk5aWx1/~/changes/2r7eGDMAwFdUD41dlSl4/frame-pallet/imports)

This is where crates are imported, especially the substrate\_ framework crates.&#x20;

All pallets will import `frame-support` and `frame-system`&#x20;

```rust
pub use pallet::*;
// other global dependencies...

#[frame_support::pallet]
pub mod pallet {
    use frame_support::pallet_prelude::*;
    use frame_system::pallet_prelude::*;
    // other pallet dependencies...
```

### Declaration of the Pallet Type

A placeholder to implement traits and methods.

```rust
    #[pallet::pallet]
    #[pallet::generate_store(pub(super) trait Store)]
    #[pallet::generate_storage_info]
    pub struct Pallet<T>(_);
```

### [Runtime Configuration Trait](https://app.gitbook.com/o/VlWTV0GJXmoHRKrDvk52/s/3UKO6MPPEQpqMJk5aWx1/~/changes/xXqaDNctfMMobhev7VOT/pallet/configuration-trait)

This is used to access features from other pallets, or constants that impact the pallet's behavior.

{% hint style="info" %}
This is the part of the code where you say "hey I'm going to create some functions that do with something I'll call `coin` and I'm going to have the be the `coin` that's defined in the other pallet....but I'm going to also cast votes, so my `votes` will be the ones defined in that other voting pallet"
{% endhint %}

The `Config` trait allows you to do the above while keeping `Generic Types` so you can change define and use something called `coin` or `votes` from some other `Pallet` defined at runtime, but swapped with some other pallet with a runtime update later on.

### [Runtime Storage](/developers/notes-about-substrate/frame-pallet/runtime-storage.md)

Have some custom data you want on the chain for users or otherwise?

`Runtime Storage` is where you do that. You declare storage items you'd like to make accessible to runtime.

### [Runtime Events](/developers/notes-about-substrate/frame-pallet/runtime-events.md)

Events are how you communicate back to people using the block chain like "transaction confirmed!" or "error! not enough cash!"

### [Hooks](/developers/notes-about-substrate/frame-pallet/hook.md)

This is  where you'd build some logic that can be executed regularly in some context, for e.g. on\_initialize.&#x20;

Basically, your blockchain's equivalent to handling webhooks.

### [Extrensics (Dispatchable Calls)](https://app.gitbook.com/o/VlWTV0GJXmoHRKrDvk52/s/3UKO6MPPEQpqMJk5aWx1/~/changes/HQOUCVHJR1sNlGKXFbuy/frame-pallet/extrinsics-dispatchable-calls)

These are functions that blockchain users can call. This is often called a `Dispatchable Call`.

#### decl\_module!

This is the macro where dispatchable calls are composed.

## A Little More on Each Topic

{% content-ref url="/spaces/3UKO6MPPEQpqMJk5aWx1/pages/XZZsP3R2cNgTclXdszq5" %}
[Imports](/developers/notes-about-substrate/frame-pallet/imports.md)
{% endcontent-ref %}

{% content-ref url="/spaces/3UKO6MPPEQpqMJk5aWx1/pages/NPuQ42X7hqPuy0X2FZfj" %}
[Runtime Configuration Trait](/developers/notes-about-substrate/frame-pallet/runtime-configuration-trait.md)
{% endcontent-ref %}

{% content-ref url="/spaces/3UKO6MPPEQpqMJk5aWx1/pages/OpksJvmpnTW3iuJ0EVBD" %}
[Runtime Storage](/developers/notes-about-substrate/frame-pallet/runtime-storage.md)
{% endcontent-ref %}

{% content-ref url="/spaces/3UKO6MPPEQpqMJk5aWx1/pages/DqAgHgl1S3fkb6eRyG3b" %}
[Runtime Events](/developers/notes-about-substrate/frame-pallet/runtime-events.md)
{% endcontent-ref %}

{% content-ref url="/spaces/3UKO6MPPEQpqMJk5aWx1/pages/EvWIt74EJqUxy0tvMIEe" %}
[Hook](/developers/notes-about-substrate/frame-pallet/hook.md)
{% endcontent-ref %}

{% content-ref url="/spaces/3UKO6MPPEQpqMJk5aWx1/pages/wO4gmHPfYALDWX8jB9SB" %}
[Extrinsics (Dispatchable Calls)](/developers/notes-about-substrate/frame-pallet/extrinsics-dispatchable-calls.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.build3.network/developers/notes-about-substrate/frame-pallet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
