Skip to main content

Basic DAO

View this sample's code on GitHub

This sample project demonstrates a basic decentralized autonomous organization (DAO) that can be deployed to the Internet Computer. The basic DAO sample code is available in Motoko and Rust. You can see a quick introduction on YouTube.

Overview

A basic_dao can be initialized with a set of accounts: mappings from principal IDs to a number of tokens. Account owners can query their account balance by calling account_balance and transfer tokens to other accounts by calling transfer. Anyone can call list_accounts to view all accounts.

Account owners can submit proposals by calling submit_proposal. A proposal specifies a canister, method, and arguments for this method. Account owners can cast votes (either Yes or No) on a proposal by calling vote. The amount of votes cast is equal to the amount of tokens the account owner has. If enough Yes votes are cast, basic_dao will execute the proposal by calling the proposal’s given method with the given args against the given canister. If enough No votes are cast, the proposal is not executed, and is instead marked as Rejected.

Certain system parameters, like the number of Yes votes needed to pass a proposal, can be queried by calling get_system_params. These system parameters can be modified via the proposal process, i.e. a proposal can be made to call update_system_params with updated values. This workflow is demonstrated below.

View the canister service definition for more details.

Prerequisites

This example requires an installation of:

  • Install the IC SDK.
  • To run the test scripts, you need to download ic-repl.
  • Clone the example dapp project: git clone https://github.com/dfinity/examples

Begin by opening a terminal window.

Step 1: Navigate into the folder containing the project's files and start a local instance of the Internet Computer with the command:

cd examples/motoko/basic_dao
dfx start --background

Step 2: Create test identities with the commands:

dfx identity new Alice --disable-encryption; dfx identity use Alice; export ALICE=$(dfx identity get-principal);
dfx identity new Bob --disable-encryption; dfx identity use Bob; export BOB=$(dfx identity get-principal);

Step 3: Deploy basic_dao with initial test accounts.

dfx deploy --argument "(record {
accounts = vec { record { owner = principal \"$ALICE\"; tokens = record { amount_e8s = 100_000_000 }; };
record { owner = principal \"$BOB\"; tokens = record { amount_e8s = 100_000_000 };}; };
proposals = vec {};
system_params = record {
transfer_fee = record { amount_e8s = 10_000 };
proposal_vote_threshold = record { amount_e8s = 10_000_000 };
proposal_submission_deposit = record { amount_e8s = 10_000 };
};
})"

Step 4: Run the ic-repl test scripts:

ic-repl tests/account.test.sh
ic-repl tests/proposal.test.sh

Security considerations and best practices

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 aspects are particularly relevant for this app: