It is an example implementation of the PSP22 Fungible Token Standard as a chain extension, supporting a multi-token system provided by the FRAME assets pallet. It effectively allows ink! contracts (L2) to interact with native assets (L1) from the chain runtime in a standardized way.
See this chapter in our ink! documentation for more details about chain extensions.
There are two parts to this example:
- Defining and calling the extension in ink!.
- Defining the extension in Substrate.
To integrate this example into Substrate you need to do two things:
-
In your runtime, use the code in
psp22-extension-example.rs
as an implementation for the traitChainExtension
in Substrate. You can just copy/paste that file as a new module, e.g.runtime/src/chain_extension.rs
. -
In your runtime, use the implementation as the associated type
ChainExtension
of the traitpallet_contracts::Config
:impl pallet_contracts::Config for Runtime { … type ChainExtension = Psp22Extension; … }
See the example contract in lib.rs
.