Proof of Existence Blockchain with Substrate

How to build a Proof of Existence Blockchain with Substrate?

August 10, 2022 13:52 PM

Existence Blockchain with Substrate

The year 2019 will be remembered for its exciting blockchain development companies and decentralized applications. Parity's Substrate has been officially released in beta just in time for the New Year.

The Blockchain with Substrate is a framework that allows users to create custom blockchains. While blockchain development normally requires you to create peer-to-peer networks, a database layer, and consensus algorithms, Substrate offers battle-tested software that you can tailor to your specific needs.

As a result of a hack on the Bitcoin network, the first proof-of-existence platform was created. It would have been difficult to create a whole blockchain platform just for this purpose at the time. Substrate makes it possible and even easier!

To demonstrate the simplicity of Substrate development, I decided to create a blockchain that is a proof-of-existence blockchain.

What is Substrate?

The substrate is an open-source modular framework that can be extended and modified to build interoperable blockchain networks such as Polkadot. It is a Software Development Kit (SDK), which was created to give developers access to all the essential elements of the blockchain and allow them to focus on the logic that will give your chain its creative personality. The following attributes make Substrate stand out among all other distributed ledger platforms:

Open

Substrate's entire toolkit and architecture are available under an open-source license. Substrate's core elements use open protocols such as JSON-RPC and libp2p, giving you the freedom to create your blockchain architecture.

Flexible

Many blockchain platforms have strongly linked sub-systems that are difficult to disengage from. Chains built on forks of other blockchains can have unobvious couplings, which can make it difficult to disconnect. The substrate can be used to create a customized blockchain that can adapt to your needs. It can also grow with them as their needs change.

Future-proof

The substrate was created to be modular and flexible. The Substrate state transition logic, which is a WebAssembly object, is a standalone WebAssembly runtime. Your nodes may be granted the power to modify the runtime, which can cause network runtime upgrades.

Interoperable

Many blockchain systems offer very limited interoperability with other ones. Substrate-Based Blockchains can communicate through cross-consensus messaging. Parachains can be attached to substrates to share the security of relay chains. They can also be used to create autonomous networks (solo chains).

What's the relationship between Substrate and Polkadot?

The Polkadot multichain network and layer-0 protocol are the foundation of Web3 development. The substrate is the main blockchain SDK that programmers use to create the parachains of the Polkadot Network. To create a para chain or part thread, you can easily incorporate substrate-based chains in Polkadot and Kusama. The substrate is the SDK that is used to create parachains. Polkadot, on the other hand, is used to protect and allow communication between the chains. All substrate-based parachains are compatible with Polkadot because they work seamlessly together.

Substrate and Polkadot are mutually beneficial, but there are not many alternatives to support the development of Polkadot. The substrate can also be used to create and maintain Polkadot parachains. Substrate does not require any connection to Kusama or Polkadot. The substrate-based chain can exist as a "solo-chain span".

Now that we have a better understanding of the relationship between Substrate and Polkadot, let's see how Substrate drives the development of the Proof of Existence Blockchain.

Blockchain Proof of Existence

This article will demonstrate how to use the substrate framework to create a proof-of-existence blockchain on the Polkadot. It also means that you'll be running your chain on the polka dot polka dot. Imagine you are the author of a book. To prove this, you will need to create a proof of existence. To implement this functionality, we will create a blockchain. You will add your name and book topic to the blockchain. It should remain immutable for all time. I won't mention blockchain use here. Let's move on to the main course.

Pre-requirements

As I have already mentioned, we will need to use the substrate framework to create our blockchain. There are two things we have to do now. We will clone the substrate-node-template and substrate-UI-template from substrate GitHub to be very fast in our development. Also, we will build the runtime pallet for our blockchain development in the pallet folder of the substrate-node-template project.

Auth-Pallet Building

The auth-pallet describes the modular and logical implementation of how our blockchain works on its chain.

#! [cfg_attr(not(feature = "std"), no_std)] use frame_support:: dispatch, decl_error, decl_event, decl_module, decl_storageDispatchResult, ensure }; use frame_system:: ensure_signed; #[cfg(test)] use sp_std::vec::vec; // standard substrate pallet package mod tests;

You can create the file lib.rs in the auth-pallet folder for the pallets of the substrate. Copy and paste the code parts. Each pallet contains the library of runtime modules to implement state transaction functions from one state on the chain to the next.

This allows for the chain to fire if an error occurs while the runtime module runs.

Decl_event: This allows the chain to fire if the state changes are successful.

Decl_module: This allows external users to interact with the functionality of the chain.

This function allows the user to save data to the chain.

dispatch

This is a requirement that the item complies with certain conditions. It is similar to the requirement of solidity programming.

These codes may make you feel bored. Let's move on to the next steps. You will then be a competent substrate developer.

 

These macros are listed on the substrate. important!!

decl_event!( EventT> pub enum where AccountId = T as defined by frame_system::Config>::AccountId, ( // This event emitted someone's claim into the chain. ClaimInsert(AccountId,Vec u8>); } ); decl_storage! { trait 'Store for Module as Proof { pub Proofs get(fn get_proof): map hasher(blake2_128_concat) T::AccountId => u8; } } decl_error! { pub enum Error for Module { /// Attempted to transfer than were available ErrorTransfer, } } decl_module! { pub struct Module for enum Call where origin: T::Origin{ // This is the ill-fire event in default fn deposit_event() = default // This function is an external function to interact with the users who want to interact with our blockchain. The first parameter will be origin somehow and anytime and then add the next params ... fn claimInsert(origin,Vec>)-> DispatchResult{ let sender = ensure_signed(origin)?; // OR // store sender's data in the chain ::insert); // emit event Self::deposit_event(RawEvent::ClaimInsert(sender,Vec>); Ok(()); } } }

Once we have coded some logic in the auth-pallet, we can run the cargo build command. Next, it will compile the wasm file for upload to our chain.

Then we will run substrate-UI-template and connect the node built on the substrate to Polkadot JS in the local environment. That's it. It's now possible to see your chain. It's amazing to have your blockchain.

Conclusion

This codebase cannot be used without this study. I focused on how to create our chain using the substrate framework. This might seem boring to you. Without the help of a substrate, it is difficult to grasp. This article is intended for those who want to master the substrate. I hope everyone can have a great journey today with this article. Thanks.

let's cut the distances today

tell us about your project

Captcha

4 + 9

=

Visit us

Plot No-one, 249, Phase IV, Udyog
Vihar, Sector 18, Gurugram,
Haryana 122022

call us

+91 8920947884

email us

[email protected]

don't think about budget just contact us and take your business beyond the sky

book free Consultation
home icon

Home

services icon

Services

technology icon

Technology

blog icon

Blog

contact icon

Contact

Coronavirus Crisis