Akıllı sözleşme, blok zinciri tabanlı bir uygulamada özerk olarak çalışabilen ve belirli koşullar altında işlemleri gerçekleştirebilen bir program parçasıdır.
Bu kodda, blok zinciri tabanlı bir uygulamada bir telefon defteri işlevselliğini sağlamak nasıl kullanılabileceğinin basit bir örneğini yaptım.
-
Burada "Telefon_Defterim" adında bir aktör (actor) tanımlanır. Aktörler, Motoko dilinde eşzamanlı işlemleri yönetmek ve paralel hesaplamalar gerçekleştirmek için kullanılan bir yapıdır.
-
Bu aktör, bir telefon defteri uygulamasını temsil eder. Telefon defterindeki her giriş, kişinin adı ve telefon numarası ile ilişkilendirilmiş bir açıklamadan oluşan bir yapı içinde tutulur.
Bu kodun işlevleri ise şunlardır:
-
insertfonksiyonu: Bir kişinin adı ve telefon numarası ile rehberde bir giriş ekler.nameparametresi, kişinin adını,entryparametresi ise kişinin telefon numarasını ve açıklamasını içeren bir veri yapısını temsil eder. -
lookupfonksiyonu: Bir kişinin adını alır ve bu kişinin rehberdeki girişini bulur. Bu fonksiyon, rehberdeki bir girişi sorgulamak için kullanılır. Eğer kişinin adı rehberde bulunursa, ilgili girişin bilgilerini döndürür. Eğer kişi rehberde bulunmazsa, null değeri döndürür.
https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/
Yapılacaklar listesi oluşturma ve yönetme. Yeni yapılacaklar ekleme. Yapılacakları tamamlanmış olarak işaretleme. Yapılacaklar listesini görüntüleme. Tamamlanmış tüm yapılacakları silme.
Kişisel görevleri yönetmek. Alışveriş listeleri oluşturmak. Proje görevlerini takip etmek. Yapılması gereken her şeyi organize etmek. import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";
<MarkdownChipRow labels={["Beginner", "Motoko"]} />
This example illustrates how to create a simple to-do checklist application.
The application is built from the following Motoko source code files:
Utils.mo: contains the core functions for adding, completing, and removing to-do checklist items.Types.mo: contains the type definition of a to-do checklist item.Main.mo: contains the actor definition and methods exposed by this canister.
This is a Motoko example that does not currently have a Rust variant.
This example requires an installation of:
- Install the IC SDK.
Begin by opening a terminal window.
Step 1: Navigate into the folder containing the project's files and start a local instance of the replica with the command:
cd examples/motoko/simple-to-do
dfx start --backgrounddfx deploydfx canister call simple_to_do addTodo '("Create a project")'
dfx canister call simple_to_do addTodo '("Build the project")'
dfx canister call simple_to_do addTodo '("Deploy the project")'dfx canister call simple_to_do showTodos("
___TO-DOs___
(1) Create a project
(2) Build the project
(3) Deploy the project")dfx canister call simple_to_do completeTodo '(1)'dfx canister call simple_to_do showTodos("
___TO-DOs___
(1) Create a project ✔
(2) Build the project
(3) Deploy the project")If you base your application on this example, we recommend you familiarize yourself with and adhere to the security best practices for developing on the Internet Computer. This example may not implement all the best practices.
For example, the following aspect is particularly relevant for this app:
- Validate inputs, since this canister processes user-provided input.