Home

Awesome

IC-PAYROLL

IC-PAYROLL is an experimental app to demonstrate a real world use case for ckBTC on the Internet Computer. It is a simple Payroll that allows users to accept and make payments using ckBTC payments.

The Internet Computer integrates directly with the Bitcoin network. This allows canisters on the Internet Computer to receive, hold, and send Bitcoin, all directly with transactions on the Bitcoin network. Chain-key Bitcoin (ckBTC) is an ICRC-1-compliant token that is backed 1:1 by Bitcoin held 100% on the IC mainnet.

For deeper understanding of the ICP < > BTC integration, see the IC wiki article on Bitcoin integration.

Features

Architecture

Backend

The backend is written in Motoko and consist of one canister, backend. It exposes the following public methods:

In addition to the public methods, the canister uses a timer to monitor ledger transactions. When a new transaction is found that matches a configured store – depending on the store settings – the canister will send a notification either by email or SMS.

Frontend

The frontend is written in Javascript/Vite/Vue/TailwindCSS. Users authenticate using the Internet Identity to access their store.

The frontend interacts with the following IC canisters:

Local deployment

Prerequisites

Use the package,,json scripts to automate the whole process

npm run start && npm run dev

This will setup the project and get it running. you can then login and start transacting

OR Step 1: Start a local instance of the Internet Computer

dfx start --clean --background

Step 2: Deploy the Internet Identity canister

Integration with the Internet Identity allows store owners to securely setup and manage their store. The Internet Identity canister is already deployed on the IC mainnet. For local development, you need to deploy it to your local instance of the IC.

dfx deploy --network local internet_identity

Step 3: Save current principal as a variable

The principal will be used when deploying the ledger canister.

export OWNER=$(dfx identity get-principal)

Step 3: Deploy the ckBTC ledger canister

The responsibilities of the ledger canister is to keep track of token balances and handle token transfers.

The ckBTC ledger canister is already deployed on the IC mainnet. ckBTC implements the ICRC-2 token standard. For local development, we deploy the ledger for an ICRC-2 token mimicking the mainnet setup.

Take a moment to read the details of the call we are making below. Not only are we deploying the ledger canister, we are also:

dfx deploy --network local --specified-id mxzaz-hqaaa-aaaar-qaada-cai ckbtc_ledger --argument '
  (variant {
    Init = record {
      token_name = "Local ckBTC";
      token_symbol = "LCKBTC";
      minting_account = record {
        owner = principal "'${OWNER}'";
      };
      initial_balances = vec {
        record {
          record {
            owner = principal "'${OWNER}'";
          };
          100_000_000_000;
        };
      };
      metadata = vec {};
      feature_flags = opt record{icrc2 = true };
      transfer_fee = 10;
      archive_options = record {
        trigger_threshold = 2000;
        num_blocks_to_archive = 1000;
        controller_id = principal "'${OWNER}'";
      }
    }
  })
'

Step 4: Deploy the index canister

The index canister syncs the ledger transactions and indexes them by account.

dfx deploy --network local icrc1_index --argument '
  record {
   ledger_id = (principal "mxzaz-hqaaa-aaaar-qaada-cai");
  }
'

Step 5: Deploy the backend canister

The backend canister manages the user configuration and sends notifications when a payment is received.

The --argument '(0)' argument is used to initialize the canister with startBlock set to 0. This is used to tell the canister to start monitoring the ledger from block 0. When deploying to the IC mainnet, this should be set to the current block height to prevent the canister from processing old transactions.

dfx deploy --network local backend --argument '(0)'

Step 6: Configure the backend canister

The backend uses Courier to send email and SMS notifications. If you want to enable notifications, you need to sign up for a Courier account and and create and API key. Then issue the following command:

dfx canister --network local call backend setCourierApiKey "pk_prod_..."

Step 7: Build and run the frontend

Run npm to install dependencies and start the frontend. The frontend will be available at http://localhost:3000.

npm install
npm run dev

Step 8: Generate did files

dfx generate backend

This generates the did files for the backend canister. You can find the generated files in the ./src/declarations/backend directory.This is what allows you to call the backend canister from the frontend.

Step 9: Login and start transacting

Go to http://localhost:3000 and login with the Internet Identity

Step 10: Get funds

npm run mint

Enter the amount of ckBTC you want to mint and the principal you want to mint to. The principal is the Internet Identity principal of the user you want to mint to. You can find the principal by logging in to the frontend and copying the principal from the URL.Also send some funds to the canister so you can receive funds when you request test tokens

Step 11: Start transacting

You can now start transacting with the app. You can send funds to other users and receive funds from other users.

Note that you need to refresh manually to see the updated balance after a transaction.

Deploying to the IC mainnet