Add collectibles to the runtime

You now have a custom pallet with the basic functions for trading digital collectibles. The next step is to add this pallet to the runtime to expose its functionality on the blockchain. Before you do that, however, take a moment to verify that you included the collectibles pallet in the manifest for the node as instructed in Add the pallet to the workspace.

To check the manifest for the workspace:

  1. Open a new terminal, if needed.
  2. Change to the workshop-node-template directory in your workspace.
  3. View the contents of the Cargo.toml file for your node workspace.

    more Cargo.toml

    You should see the collectibles pallet listed as a member of the workspace. For example:

    [workspace]
    members = [
        "node",
        "pallets/collectibles",
        "pallets/template",
        "runtime",
    ]
    [profile.release]
    panic = "unwind"

    If the collectibles pallet is included, you're ready to update the runtime and complete the first part of the workshop.

Update runtime files

To add the collectibles pallet to the runtime:

  1. Open the runtime/Cargo.toml file in a text editor and add the collectibles pallet to the local dependencies and standard features for the runtime.

    For example:

    # Local Dependencies
    pallet-template = { version = "4.0.0-dev", default-features = false, path = "../pallets/template" }
    collectibles = { default-features = false, path = "../pallets/collectibles" }
    
    [features]
    default = ["std"]
    std = [
    ...
        "collectibles/std",
    ...
  2. Save your changes and close the file.
  3. Open the runtime/src/lib.rs file in a text editor.
  4. Import the collectibles pallet into the runtime.

    /// Import the collectibles pallet.
    pub use collectibles;
  5. Implement the configuration trait for the collectibles pallet.

    impl collectibles::Config for Runtime {
        type RuntimeEvent = RuntimeEvent;
        type Currency = Balances;
        type CollectionRandomness = RandomnessCollectiveFlip;
        type MaximumOwned = frame_support::pallet_prelude::ConstU32<100>;
    }
  6. Add the pallet to the construct_runtime! macro.

    construct_runtime!(
        pub struct Runtime
        where
            Block = Block,
            NodeBlock = opaque::Block,
            UncheckedExtrinsic = UncheckedExtrinsic,
        {
            System: frame_system,
            RandomnessCollectiveFlip: pallet_randomness_collective_flip,
            Timestamp: pallet_timestamp,
            Aura: pallet_aura,
            Grandpa: pallet_grandpa,
            Balances: pallet_balances,
            TransactionPayment: pallet_transaction_payment,
            Sudo: pallet_sudo,
            TemplateModule: pallet_template,
            Collectibles: collectibles,
        }
    );
  7. Compile the blockchain node with the updated runtime by running the following command:

    cargo build --release

    After the node compiles, your custom pallet is ready for action.

Access the collectibles pallet

Now that you have a freshly compiled node, you can restart the blockchain and use your new pallet.

  1. Start the blockchain node by running the following command:

    ./target/release/node-template --dev
  2. Open the Polkadot/Substrate Portal and connect to your local Development node.

    Connect to the local nodet
    )

  3. Click Developer and select Extrinsics.
  4. Select the collectibles pallet and view the list of callable functions.

    Callable functions in the collectibles pallet
  5. Select the createCollectible function, click Submit Transaction, then click Sign and Submit.
  6. Click Network and select Explorer to see the event emitted for creating a new collectible.

    CollectibleCreated event

    You can use the Polkadot/Substrate Portal to test that functions, events, and errors work as expected. However, for your application to draw users, you'll want to develop a custom interface that lets users browse and bid on collectibles that other users create and put up for sale. Building an inviting interface is an art unto itself, so for this workshop we'll keep things simple and not delve into what the application should look like or the user experience it should provide. In most cases. you'll want to use TypeScript and a web development framework such as React, Vue, or Angular to build the front-end for the application that runs on your blockchain.

    Instead of focusing on the front-end, the next part of the workshop highlights more complex logic, testing, and converting your single node solo chain into a parachain.