noxzym / icp-azle-201

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Things to be explained in the course:

  1. What is Ledger? More details here: https://internetcomputer.org/docs/current/developer-docs/integrations/ledger/
  2. What is Internet Identity? More details here: https://internetcomputer.org/internet-identity
  3. What is Principal, Identity, Address? https://internetcomputer.org/internet-identity | https://yumimarketplace.medium.com/whats-the-difference-between-principal-id-and-account-id-3c908afdc1f9
  4. Canister-to-canister communication and how multi-canister development is done? https://medium.com/icp-league/explore-backend-multi-canister-development-on-ic-680064b06320

Getting started

To get started developing in the browser, click this button:

Open in Gitpod

If you rather want to use GitHub Codespaces, click this button instead:

Open in GitHub Codespaces

NOTE: After deploying your canisters in GitHub Codespaces, run ./canister_urls.py and click the links that are shown there.

If you prefer running VS Code locally and not in the browser, click "Codespaces: ..." or "Gitpod" in the bottom left corner and select "Open in VS Code" in the menu that appears. If prompted, proceed by installing the recommended plugins for VS Code.

To develop fully locally, first install Docker and VS Code and start them on your machine. Next, click the following button to open the dev container locally:

Open locally in Dev Containers

How to deploy canisters implemented in the course

Ledger canister

./deploy-local-ledger.sh - deploys a local Ledger canister. IC works differently when run locally so there is no default network token available and you have to deploy it yourself. Remember that it's not a token like ERC-20 in Ethereum, it's a native token for ICP, just deployed separately. This canister is described in the dfx.json:

	"ledger_canister": {
  	"type": "custom",
  	"candid": "https://raw.githubusercontent.com/dfinity/ic/928caf66c35627efe407006230beee60ad38f090/rs/rosetta-api/icp_ledger/ledger.did",
  	"wasm": "https://download.dfinity.systems/ic/928caf66c35627efe407006230beee60ad38f090/canisters/ledger-canister.wasm.gz",
  	"remote": {
    	"id": {
      	"ic": "ryjl3-tyaaa-aaaaa-aaaba-cai"
    	}
  	}
	}

remote.id.ic - that is the principal of the Ledger canister and it will be available by this principal when you work with the ledger.

Also, in the scope of this script, a minter identity is created which can be used for minting tokens for the testing purposes. Additionally, the default identity is pre-populated with 1000_000_000_000 e8s which is equal to 10_000 * 108 ICP. The decimals value for ICP is 108.

List identities: dfx identity list

Switch to the minter identity: dfx identity use minter

Transfer ICP: dfx ledger transfer <ADDRESS> --memo 0 --icp 100 --fee 0 where:

  • --memo is some correlation id that can be set to identify some particular transactions (we use that in the marketplace canister).
  • --icp is the transfer amount
  • --fee is the transaction fee. In this case it's 0 because we make this transfer as the minter idenity thus this transaction is of type MINT, not TRANSFER.
  • <ADDRESS> is the address of the recipient. To get the address from the principal, you can use the helper function from the marketplace canister - getAddressFromPrincipal(principal: Principal), it can be called via the Candid UI.

Internet identity canister

dfx deploy internet_identity - that is the canister that handles the authentication flow. Once it's deployed, the js-agent library will be talking to it to register identities. There is UI that acts as a wallet where you can select existing identities or create a new one.

Marketplace canister

dfx deploy dfinity_js_backend - deploys the marketplace canister where the business logic is implemented. Basically, it implements functions like add, view, update, delete, and buy products + a set of helper functions.

Do not forget to run dfx generate dfinity_js_backend anytime you add/remove functions in the canister or when you change the signatures. Otherwise, these changes won't be reflected in IDL's and won't work when called using the JS agent.

Marketplace frontend canister

dfx deploy dfinity_js_frontend - deployes the frontend app for the dfinity_js_backend canister on IC.

About


Languages

Language:JavaScript 60.2%Language:TypeScript 30.8%Language:Python 4.4%Language:Shell 2.3%Language:CSS 1.5%Language:HTML 0.8%