ICP Developer Guide -Chapter 2

The Building Block of ICP-Canister

Canister is a fundamental computational unit that combines both code and state. It is essentially a smart contract or a container that runs on the Internet Computer blockchain. Canisters are designed to be autonomous, scalable, and interoperable, enabling developers to build decentralized applications (dApps) and services.

Key Features of a Canister:

Code and State:

  1. Autonomous:
    • Canisters operate independently and can interact with other canisters or external systems via messages.
  2. Scalable:
    • The Internet Computer allows canisters to scale horizontally by distributing their workload across multiple nodes in the network.
  3. Interoperable:
    • Canisters can communicate with each other through message passing, enabling complex decentralized applications to be built by composing multiple canisters.
  4. Upgradable:
    • Developers can update the code of a canister without losing its state, making it easier to maintain and improve applications over time.

Cycle

n the Internet Computer (ICP), a Cycle is a computational unit used to pay for the execution of smart contracts (called canisters). It functions similarly to “gas” in Ethereum but is designed to be more predictable and cost-efficient.

Key Features of Cycles in ICP:

  1. Resource-Based Pricing – The cost of computation, storage, and network usage is measured in cycles.
  2. Stable Pricing Model – Unlike Ethereum’s gas, the cost of cycles is tied to real-world resources (compute and storage) rather than being market-driven.
  3. Conversion from ICP Tokens – ICP tokens can be converted into cycles to fund canister execution. The conversion rate is adjusted to maintain price stability. XDR (Special Drawing Rights) is used as a reference unit to determine the cost of converting ICP tokens to cycles in a stable manner.(1T Cycle = 1 XDR ~ USD1.321)
  4. Canister Management – Cycles are stored within canisters and consumed as operations are performed. When a canister runs out of cycles, it stops executing until refueled.

Cycle Usage in ICP:

  • Computation – Each instruction executed by a canister consumes cycles.
  • Storage – Data stored in the canister costs cycles over time.
  • Inter-canister Calls – Messaging between canisters also consumes cycles.
  • Network Operations – Data transmission to and from the Internet Computer incurs cycle costs.

Creation of a Cycle Wallet in Local Network

To create a cycle wallet in the local network, you start the local network in a clean mode using the following command:

dfx start –background –clean

Running the following command first time to create a cycle wallet automatically with 100T cycles in local network, otherwise it will return the cycle wallet id only.

dfx identity get-wallet

The following command will return the balance in the wallet:

dfx wallet balance

Motoko-The native programming language of ICP

Motoko is a programming language specifically designed for the Internet Computer (ICP) blockchain. It is optimized for writing smart contracts (called canisters) that run directly on the ICP network.

Key Features of Motoko

  1. Actor-Based Model – Uses the actor model to handle concurrency and asynchronous execution efficiently.
  2. Type-Safe & Memory-Safe – Strongly typed language that prevents common programming errors.
  3. Designed for Web3 – Integrates directly with the Internet Computer, supporting scalability, persistence, and seamless upgrades.
  4. Automatic Garbage Collection – Handles memory management internally.
  5. WebAssembly Compilation – Runs as WebAssembly (Wasm) for efficient execution on the ICP blockchain.
  6. Interoperability – Can interact with Rust, JavaScript, and other WebAssembly languages.

Create and Deploy Canisters

Creating a canister on the Internet Computer (ICP) involves a few simple steps. Below is a basic guide:

Start local network in background

dfx start –background

Create hello world project

dfx new hello

Select a backend language, you may choose Motoko, Rust, Python or Typescript, as shown below. We choose Motoko for our illustration.

Then select a Frontend language as follows. We choose React for illustration.

Then add extra features as follows, we choose Intenet Identity:

Pressing enter to confirm will create all necessary files and install dependencies, and arrive at the start up screen as shown below. A project with the folder name hello will be created.

The project architecture is as shown below:

Deploying Canister on Local Network

To deploy the hello project you have just created on a local network, use the following command:

dfx deploy

The following screen shows successful deployment, otherwise there will be errors:

You may access the frontend URL via the link generated.

The frontend UI is as illustrated below:

Deploying Canister on the IC Mainnet

The command to deploy the canister on the IC mainnet is

dfx deploy –network ic

If the deployment on the IC blockchain is successful, the output will display the URLs of both the frontend and backend, as shown below:

The frontend URL can be accessed on the desktop browser and the browser of the mobile devices. It does not need to register a domain nor a central server to host the web app, it is fully on chain.

In this example, accessing the frontend URL with the link will display a certificate generator app, as shown below:

Obtaining Cycles

You need cycles to deploy your ICP app on the mainnet. There are two ways to obtain the cycles, one way is to redeem the coupon codes if you are given some free coupons, the other way is to buy icp tokens and convert them to cycles.

Method 1: Redeeming cycles from coupon codes

The command to redeem the cycles with coupon code is as follows:

dfx cycles redeem-faucet-coupon –network ic <COUPON_CODE>

Example: dfx cycles redeem-faucet-coupon –network ic CE3A9-BA578-CD44B

To check cycles balance in the wallet, use the following command:

dfx cycles –network ic balance

Method 2: Converting ICP tokens to cycles

First of all you must create an empty canister using ICP token using the following command:

dfx ledger –ic create-canister <principal-identifier> –amount <ICP tokens>

You may use the following command to obtain the principal identifier:

dfx identity get-principal

Example to get the principal identifier:

Then use the following command to convert ICP tokens to cycles:

dfx ledger –ic create-canister zxyfn-yljyi-bn6dy-ixi7n-jez74-nk723-pvj3m-jykes-dhqon-3ktql-uae –amount 0.3

To check canister status on the mainnet, use the following command:

dfx canister –network ic status <canister_id>

The status is as shown below:

*You can obtain canister id on the ic mainnet using the command: dfx canister id <canister name>–network ic

Appendix: List of dfx commands

List all accounts in the device

dfx identity list

Show current identity

dfx identity whoami

Use a particular identity

dfx identity use <Identity Name>

Get ICP Tokens balance

dfx ledger balance

Top up cycles into cycle wallet or canister by converting ICP Tokens

dfx ledger –network ic top-up <wallet id or canister id> –amount <icp tokens>

Example: Add 4T cycles to your backend canister

dfx ledger top-up –network ic <canister_backend >–amount 4.0

Top up cycles directly

dfx canister –network ic deposit-cycles amount <canister_backend>

Example: Deposit 4T cycles to your backend canister

dfx canister –network ic deposit-cycles 4000000000000 weather_app_backend

To remove your identity in the device

dfx identity remove <identity name>

To get canister basic info

dfx canister –network ic info

To stop local network

dfx stop

To list the controllers of the canister:

dfx canister info ic_minter_backend

Driving Financial Inclusion with Blockchain

According to the World Bank, financial inclusion refers to the provision of accessible and affordable financial products and services that cater to the needs of individuals and businesses. This encompasses various aspects such as transactions, payments, savings, credit, and insurance, all delivered responsibly and in a sustainable manner .

The World Bank Group acknowledges the significant role of financial inclusion in combating extreme poverty and fostering shared prosperity . The initial stride towards achieving broader financial inclusion is facilitated by access to a transaction account, enabling individuals to securely hold and conduct various monetary transactions such as sending and receiving payments. In addition, individuals will have the opportunity to establish financial security through various means, including saving money, investing in financial products to meet their children’s education and retirement needs, and adequately preparing for potential financial challenges.

Since their inception, blockchain technologies have demonstrated tremendous potential in promoting financial inclusion and streamlining the formalization of remittances (Rella, 2019). Blockchain technology presents an array of possibilities, encompassing faster, cost-effective, and highly secure payment processing. Furthermore, its distributed ledger capability instills enhanced trust among participants. Originally conceived as a foundation for virtual currencies, blockchain has now found extensive utilization across various industries, notably in the realm of payments .

Furthermore, blockchain technology facilitates global payment processing and various other transactions through encrypted distributed ledgers, ensuring dependable real-time transaction verification. Consequently, intermediaries such as clearing houses and correspondent banks are rendered unnecessary. In addition, blockchain applications have gained significant appeal for remittances, particularly for transferring small amounts of money, thanks to their instantaneous, affordable, and traceable transactions that support multiple currencies across domestic and international mobile networks. Moreover, these applications can effectively store a variety of currencies within diverse mobile networks, highlighting the potential of blockchain-based systems.

After conducting comprehensive analysis of relevant prior research, it is evident that blockchain technology possesses the potential to facilitate digital financial inclusion across various domains. This technology finds application in diverse areas such as financial transactions, savings optimization, credit extension, and insurance provision . In conclusion, sustainable development can be achieved through various avenues, and one promising approach is leveraging blockchain technology to enhance financial inclusion. Governments, particularly those in developing economies, must prioritize serious consideration of blockchain investments to foster greater financial inclusion.

What is Web3?

Web3 and metaverse have been two buzzwords for the year 2022, but according to the World Economic Forum, Web 3 is essentially a synonym for the metaverse. Therefore, I wish to discuss the two concepts together instead of writing two articles.

What is Web3.0? It can simply be understood from the following aspects:

  • Web1.0 is “read-only”;
  • Web2.0 is “readable + writable” (read + write);
  • Web3 is “read+write+own” (read+write+own).

Firstly, web1.0 is represented by websites Yahoo and Sina, which solely provide information to users . During this era, most users can only read information on the web while very few website developers could create content, I was one of them. I created my first website in 1995 titled ‘Visual Basic Tutorial” which still ranks top in Google search for the keyword ‘Visual Basic’. Web2.0 is an interactive web comprising blogs, social media like Facebook, Instagram, Twitter, Whatsapp, WeChat, Tiktok and more, which users can interact and generate content. On the other hand, web3.0 not only allows users to generate content but the content data is owned by the user, not controlled by the platform.

Secondly, we can define the web revolution by the degree of decentralization. Simply put, web1.0 is semi-centralized, Web2.0 is centralized and web3 is fully decentralized.

Comparison between Web 1.0, Web 2.0 and Web 3.0

In the Web1.0 era, decentralized personal websites formed half of the Web while the other half were centralized, both sides formed a semi-decentralized ecosystem. In the Web2.0 era, information islands are formed, and large companies such as FAANG monopolize the web and control users’ data and while numerous individual and SME websites formed a small portion of the web. On the other hand, web3.0 will be purely decentralized where data is owned and controlled by users. Web 3 is a concept for the next generation of the internet. It is the evolution of how users are able to control and own their creations and online content, digital assets and online identities. In Web 3, however, users can create content while owning, controlling and monetizing them through the implementation of blockchain and cryptocurrencies.

Data privacy is another issue of the current Web 2.0 internet. While the centralized entities have full control over the access to the service, they have full control over the users’ data. Users register to access a service and give up their precious private data and content in exchange for the convenience of the service, by agreeing to the terms of services. However, in Web3, not a single entity has control over the access to the service as it’s open to everyone. No registration is needed, users then have complete control over their private data, but at the same time, users have to take the responsibility to protect their own data and assets as they will become the only custodians.

The third aspect:

Web1.0 and Web2.0 are information Internet while Web3 is the Internet of Value. Web1.0 and Web2.0 are essentially transmitting information and focusing on consumption; while Web3 is transmitting value and creating wealth. Therefore, Web3 can be simply understood as the Internet powered by blockchain technology. It will solve the current Internet “central monopoly” problem, help users regain their data sovereignty, and recreate a better ecosystem in the digital world. Internet world. If you really understand the above changes, then you will understand that Web3 is revolutionary.

Key features of Web3 are:

Decentralized

Web3 data are typically stored in decentralized ledger like blockchain, so no single system has access to it all. It is dispersed across multiple platforms. This facilitates decentralized access and eliminate single point of failure .

Permissionless

The decentralized web can be accessed by users without requiring special permissions and KYC. Users will not need to disclose their personal information to access specific services. There will be no need to compromise privacy or share any other information.

Secure

Web 3 is more secure since decentralization makes it more difficult for hackers to target specific databases. Besides that, all data are encrypted based on cryptographic hash which add a security layer to the distributed database system.

Why we don’t call web3 as web3.0? Because they are fundamentally different.

Differences between web3 and web3.0

Web 3.0 aka semantic web focuses on efficiency and intelligence by reusing and linking data across websites. Web3 aka the decentralized web, however, puts a strong emphasis on security and empowerment by returning control of data and identity to users.

Semantic web uses a central place called the solid pod to store all user data, enabling users to handle third-party access to their data. Solid pods also issue a unique WebID for users that act as an identity within the ecosystem. In the blockchain-based web3, users can store their data in a cryptocurrency wallet, which they can access using their private keys.

Additionally, they both use different technologies to implement their purpose of data security. Web3 uses blockchain technology, while in web 3.0, certain data interchange technologies like RDF, SPARQL, OWL, and SKOS are used.

Data in web3 is difficult to modify or delete since it is scattered across multiple nodes; however, data in web3.0 can be changed effortlessly. Furthermore, the data stored in the solid pod is centralized, while the keys stored in crypto wallets provide access to the data of assets that reside on a blockchain

The differences are summarised in the following table:

ParameterWeb3Web3.0
Distribution ModelDecentralized peer-to-peerClient/Server
ProtocolBlockchain/ipfshttp/https
Relationship to World Wide WebAn Alternative to the World Wide WebThe continuation of the World Wide Web
VisionEliminates intermediaries and emphasis on security and empowerment by returning control of data and identity to users.  Evolving to a semantic web to make web content machine readable.


To learn more about Web3, please check out my book:

Reference

What is NFT?

If you have been following the crypto trends in the past one or two years, you will know that Decentralized Finance has grown exponentially in 2020 where many DeFi platforms were deployed. However, enter the year 2021, the DeFi growth has somehow slowed and seems to have been overtaken by another emerging trend, the NFT industry.

The NFT craze started when Jack Dorsey, Twitter’s founder, and CEO, auctioned his first-ever tweet(on March 21, 2006) as a nonfungible token (NFT) and was bought using ETH for $2.9 million. Since then many NFTs were successfully sold for astronomical dollar values, like the artwork named “Everydays: the First 5000 Days.” by the artist Beeper which was sold for $69 million!

So why do people are crazy about NFTs and willing to spend so much money on them? What is NFT after all? According to Wikipedia, a  non-fungible token (NFT) is a unit of data stored on a distributed digital ledger, aka blockchain, that certifies a digital asset to be unique and therefore not interchangeable. In contrast, a fungible token is a kind of digital asset that is not unique and therefore interchangeable. An NFT represents real-world objects like art, music, in-game items, videos, real estate, and more. They are bought and sold online, frequently with cryptocurrency, and they are usually encoded with blockchain technology.

The following table illustrates the differences between NFT and fungible tokens.

Fungible TokensNon-fungible Tokens
Interchangeable
A fungible token can be exchanged with any other fungible token of the same type. It is like exchanging a dollar bill with another dollar bill and the value is still the same.
Non-Interchangeable
A non-fungible token cannot be exchanged with another non-fungible token of the same type. It is like your passport or ID, they cannot be exchanged.
Uniform
Each fungible token is identical to all other fungible tokens of the same type. For example, your one-dollar bill is the same as John’s one dollar bill.
Unique
Each token is unique and different from all other tokens of the same type. For example, your bank account is not the same as John’s bank account
Divisible
A fungible token can be divided into smaller units and the total value is still the same. For example, you can divide a dollar bill into two 50 cents or five 20 cents and the total value is still the same.
Non-divisible
The non-fungible token cannot be divided into smaller units. The basic unit is one token and one token only. For example, your driving license.
ERC-20 Standard
The Ethereum Standard is used for issuance tokens to be used as cryptocurrencies.
ERC-721 Standard
The Ethereum Standard is used for the issuance of unique, non-fungible tokens. The most well-known case is CryptoKitties, which is a virtual collectibles marketplace where each kitty is unique.

NFT has several properties that help to improve processes and things. First, it can prove and authenticate the ownership of an asset or information, making it suitable for fraud and counterfeit prevention. Therefore, it can be used in the KYC procedure, issuing academic degrees and other educational certificates. Besides that, it can be used in areas that need authentication and proof of ownership and information, such as art, collectibles, badges, voting & elections, loyalty programs, in-game items, copyright, supply chain tracking, medical data, software licenses, warranties, real assets and more. Next, NFT is easily transferable and tradeable by capitalizing the blockchain network, without the need of intermediaries, all you need is a crypto wallet like MetaMask.

The history of NFTs began with the emergence of colored coins on the Bitcoin network(Opensea, n.d.). Rare Pepes, illustrations of the Pepe the Frog character built on the Bitcoin counterparty system, were among the first NFT projects. Some of them actually sold on eBay, and a set of Rare Pepes later sold in a live auction in New York. However the colored coins NFT projects did not gain traction in the mainstream.

Cryptopunk was the first Ethereum based NFT project which created 10,000 unique collectible punks with proof of ownership stored on the Ethereum blockchain. This is the project inspired that the modern CryptoArt movement. It was an inspiration for the Ethereum ERC-721 standard that powers most digital art and collectibles. No two punks are alike, and each one of them can be officially owned by a single person on the Ethereum blockchain. Originally, they could be claimed for free by anybody with an Ethereum wallet, but all 10,000 were quickly claimed. Now they must be purchased from someone on the Ethereum marketplace contract where you can buy, bid on, and offer punks for sale. To learn more, check out the website: https://www.larvalabs.com/cryptopunks

Though Cryptopunk was the first Ethereum based NFT, the first NFT project that made an inroad into the mainstream was the Ethereum based CryptoKitties. Launched in 2017, CryptoKitties featured a primitive on-chain game that allowed users to breed digital cats together to produce new cats of varying rarity. The first-generation cats were auctioned off and new cats could also be sold on a secondary market. At the height of the craze, sales of CryptoKitties nearly touched 5,000 ETH in volume, with Founder Cat #18 selling for 253 ETH ($110,000 at the time of sale). These high prices drew more users into the NFT gold rush.

Today, a couple of NFT platforms have been developed to help users create and mint NFT digital assets, the biggest one being Opensea. It claimed that it is the world’s first and largest NFT marketplace that lets users discover, collect and sell extraordinary NFTs.

References

DeFi Products

In this article, I shall discuss the types of DeFi products and services available in the crypto markets. Popular DeFi products include decentralized exchanges, loan and savings markets, tokenized physical assets such as gold, derivatives, forecasting/betting markets, payment, insurance, asset management, and more.

The complete list of DeFi products are as shown in the following Figure.

DeFi loan and savings markets allow you to lend, borrow, or deposit money in a platform. Among the popular loan and savings platforms are Compound, Aave, MakerDAO, Fulcrum, dYdX, and more. If you lend out your digital assets by depositing them in a liquidity pool, you will earn interest over a period.  On the other hand, you can borrow a digital asset by giving another digital asset as a collateral. The collateral is usually ETH but can be other cryptoassets. The debt has an accruing interest which is to be paid off along with the principal.

Decentralized exchanges or DEXs are like stock exchanges but run by smart contracts on the Ethereum blockchain. While both allow you to trade assets, decentralized exchanges only trade cryptoassets and do not require centralized authorities to manage the trading. They run on autopilot 24/7. Therefore, it offers fantastic opportunity to anyone in the world to have access to invest in digital assets, particularly the unbanked and underserved.

In a nutshell, DeFi products allows you to use your digital assets to secure a loan and use that loan to invest in some other digital assets that you expect to gain higher returns. You may also leverage on your collateral to secure more loans to purchase more assets with the expectation that the value of the assets will appreciate, not unlike real estate investment. Besides, you can lend your assets in a lending and borrowing market to earn more attractive interest than banks.

In addition, you may contribute your assets to liquidity pools in the DeFi money market to earn rewards. If your risk appetite is high, you may trade with margin in many different types of Decentralized exchanges. You can even expose yourself to higher risk by leveraging. The list goes on, so do not miss the opportunities!