Creating Our Runtime

We have now established two different Pallets for our blockchain: the System and Balances Pallet.

How do these pallets work together to create a unified blockchain system?

For that, we will need to create a Runtime.

What is the Runtime?

Remember that there is a separation between the blockchain client and the state transition function of our blockchain.

You can think of the runtime as the accumulation of all logic which composes your state transition function. It will combine all of your pallets into a single object, and then expose that single object as the entry point for your users to interact with.

Certainly this sounds pretty abstract, but it will make more sense as we complete this tutorial.

Create the Runtime

Just like our Pallets, our Runtime will be represented with a simple struct, however in this case, the fields of our struct will be our Pallets!

Complete the instructions for creating a new runtime which includes our System and Balances pallets. For this, you will need to take advantage of the new() functions we exposed for each of the Pallets.

Make sure your code is formatted and everything is still compiling. Compiler warnings about "never read/used" are okay.

mod balances;
mod system;

// This is our main Runtime.
// It accumulates all of the different pallets we want to use.
pub struct Runtime {
	/* TODO:
		- Create a field `system` which is of type `system::Pallet`.
		- Create a field `balances` which is of type `balances::Pallet`.
	*/
}

impl Runtime {
	// Create a new instance of the main Runtime, by creating a new instance of each pallet.
	fn new() -> Self {
		/* TODO: Create a new `Runtime` by creating new instances of `system` and `balances`. */
		unimplemented!()
	}
}

fn main() {
	println!("Hello, world!");
}
mod balances;
mod system;

// This is our main Runtime.
// It accumulates all of the different pallets we want to use.
pub struct Runtime {
	system: system::Pallet,
	balances: balances::Pallet,
}

impl Runtime {
	// Create a new instance of the main Runtime, by creating a new instance of each pallet.
	fn new() -> Self {
		Self { system: system::Pallet::new(), balances: balances::Pallet::new() }
	}
}

fn main() {
	println!("Hello, world!");
}
diff --git a/src/main.rs b/src/main.rs
index 815fd741..24ff8681 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,23 @@
 mod balances;
 mod system;
 
+// This is our main Runtime.
+// It accumulates all of the different pallets we want to use.
+pub struct Runtime {
+	/* TODO:
+		- Create a field `system` which is of type `system::Pallet`.
+		- Create a field `balances` which is of type `balances::Pallet`.
+	*/
+}
+
+impl Runtime {
+	// Create a new instance of the main Runtime, by creating a new instance of each pallet.
+	fn new() -> Self {
+		/* TODO: Create a new `Runtime` by creating new instances of `system` and `balances`. */
+		unimplemented!()
+	}
+}
+
 fn main() {
 	println!("Hello, world!");
 }
diff --git a/src/main.rs b/src/main.rs
index 24ff8681..2d9887b5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,17 +4,14 @@ mod system;
 // This is our main Runtime.
 // It accumulates all of the different pallets we want to use.
 pub struct Runtime {
-	/* TODO:
-		- Create a field `system` which is of type `system::Pallet`.
-		- Create a field `balances` which is of type `balances::Pallet`.
-	*/
+	system: system::Pallet,
+	balances: balances::Pallet,
 }
 
 impl Runtime {
 	// Create a new instance of the main Runtime, by creating a new instance of each pallet.
 	fn new() -> Self {
-		/* TODO: Create a new `Runtime` by creating new instances of `system` and `balances`. */
-		unimplemented!()
+		Self { system: system::Pallet::new(), balances: balances::Pallet::new() }
 	}
 }