Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 1.63 KB

README.md

File metadata and controls

47 lines (34 loc) · 1.63 KB

PSP22 Chain Extension Example

What is this example about?

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.

Chain-side Integration

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 trait ChainExtension 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 trait pallet_contracts::Config:

    impl pallet_contracts::Config for Runtime {type ChainExtension = Psp22Extension;}

ink! Integration

See the example contract in lib.rs.

Disclaimer

⚠️ This is not a feature-complete or production-ready PSP22 implementation. This example currently lacks proper error management, precise weight accounting, tests (these all might be added at a later point).