Skip to content

Commit

Permalink
Merge pull request #2935 from dfinity/add-ic-js
Browse files Browse the repository at this point in the history
Add doc on ic-js
  • Loading branch information
jessiemongeon1 authored May 17, 2024
2 parents 0645b3f + 472b2be commit 1858202
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 16 deletions.
4 changes: 3 additions & 1 deletion docs/developer-docs/daos/nns/nns-app-quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ All changes to the configuration and behavior of the Internet Computer are contr

The requests for changes and updates to the network are submitted to the NNS in the form of **proposals**. The NNS decides to adopt or reject proposals based on voting activity by neuron holders.

This guide will showcase how to interface with the NNS through the NNS dapp. You can interact with the NNS through other tools, such as [quill](/docs/current/developer-docs/developer-tools/cli-tools/quill-cli-reference/quill-parent) and [ic-js](https://github.com/dfinity/ic-js/tree/main/packages/nns).

## What are neurons?

For network participants to be able to vote on proposals, they need to lock up a stake of ICP utility tokens for a given period of time to create a representative called a **neuron**.
Expand All @@ -39,7 +41,7 @@ When a person or organization has ICP utility tokens locked up in a neuron, they
### Unlocking the stake held by a neuron

After network participants create a neuron, the locked balance of ICP utility tokens can only be unlocked by fully **dissolving** the neuron.
It's **dissolve delay** determins the time it takes for a neuron to be unlocked once it is but in the dissolving state. A dissolving neuron can always be put back int the non-dissolving state. When the dissolve timer reaches zero, the neuron owner or an authenticated custodian can dissolve the neuron and unlock the neuron's balance of ICP .
It's **dissolve delay** determines the time it takes for a neuron to be unlocked once it is but in the dissolving state. A dissolving neuron can always be put back int the non-dissolving state. When the dissolve timer reaches zero, the neuron owner or an authenticated custodian can dissolve the neuron and unlock the neuron's balance of ICP .

The dissolved neuron ceases to exist and the stake of ICP utility tokens that the neuron represented is released to the appropriate ledger canister account.

Expand Down
11 changes: 11 additions & 0 deletions docs/developer-docs/daos/sns/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ that stores the network topology etc.).
There are also a few canisters that only exist on the SNS, most notably the decentralization
swap canister that is used during the launch process of an SNS.


## SNS as a system functionality (connection to the NNS community)
SNSs are provided as a system functionality by the Internet Computer Protocol in that the code for the SNS canisters
is maintained by the Internet Computer Protocol. ([Learn about alternative ways to use the SNS code or how to create a DAO.](#dao-alternatives))
Expand Down Expand Up @@ -167,3 +168,13 @@ In more detail, it is controlled by the NNS root canister.
After a successful decentralization swap, SNS tokens are owned and the SNS is governed
by a large community.
The ICP that were collected are in an SNS-owned treasury.

## Interacting with an SNS

To interact with or participate with an SNS, the following tools and interfaces can be used:

- [NNS dapp](https://nns.ic0.app).

- [quill](/docs/current/developer-docs/developer-tools/cli-tools/quill-cli-reference/quill-parent).

- [ic-js](https://github.com/dfinity/ic-js/tree/main/packages/sns).
8 changes: 5 additions & 3 deletions docs/developer-docs/defi/icp-tokens/using-the-ledger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ There are multiple ways to interact with the ICP ledger. They depend on whether
This guide will discuss the different ways to interact with the ICP ledger. In this guide, the following workflows will be covered:
- `dfx ledger`: the built in `dfx` shortcut for interacting with the ICP ledger.
- `dfx canister`: the generic canister call from `dfx`.
- `nns-js`: interact with the ICP ledger from your web app.
- [ledger-icp](https://github.com/dfinity/ic-js/tree/main/packages/ledger-icp) JavaScript library.
- `ic-cdk`: inter-canister calls for the ICP ledger.

## Interacting with ICP ledger via `dfx ledger`
Expand Down Expand Up @@ -217,8 +217,10 @@ It is a similar format but you will only receive the CBOR encoded block:

## Interact with ICP ledger from your web application

In order to simplify working with ICP ledger from JavaScript applications, you can use the [nns-js library](https://github.com/dfinity/nns-js).
In order to simplify working with ICP ledger from JavaScript applications, you can use the [ledger-icp](https://github.com/dfinity/ic-js/tree/main/packages/ledger-icp) JavaScript library.
.
To interact with the ICRC-1 endpoints of the ICP ledger you can have a look at the guide on [interacting with an ICRC-1 ledger](/docs/current/developer-docs/defi/icrc-1/using-icrc1-ledger).

## Interacting with ICP from a canister (inter-canister calls via `ic-cdk`)
You can look at the documentation of [inter-canister calls] (/docs/developer-docs/backend/rust/intercanister) to see how you can interact with the another canister from inside a canister. This guide will give you a couple of examples on how to make such a call in the case of the ICP ledger.

Expand Down Expand Up @@ -251,7 +253,7 @@ Or, it can be added to the `Cargo.toml` file:
icrc-ledger-types = "0.1.1"
```

The documentation for this crate can be found [here](https://docs.rs/icrc-ledger-types/0.1.1/icrc_ledger_types/).
[View the documentation for this crate](https://docs.rs/icrc-ledger-types/0.1.1/icrc_ledger_types/).


### Receiving ICP
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-docs/defi/icrc-1/using-icrc1-ledger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";
There are two main ways to interact with an ICRC-1 ledger.
- `dfx canister`: the generic canister call from `dfx`.
- `ic-cdk`: inter-canister calls for the ICRC-1 ledger.
- `ledger-icrc-js`: a library for interfacing with ICRC-1 ledger on the Internet Computer.
- [`ledger-icrc-js`](https://github.com/dfinity/ic-js/tree/main/packages/ledger-icrc): a library for interfacing with ICRC-1 ledger on the Internet Computer.

## ICRC-1 and ICRC-1 extension endpoints

Expand Down
2 changes: 1 addition & 1 deletion docs/developer-docs/developer-tools/on-chain/cdks.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
keywords: [intermediate, cdk, cdks, overview]
keywords: [intermediate, cdk, cdks, overview, azle, kybra, typescript, python, solidity, bitfinity]
---

import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";
Expand Down
88 changes: 88 additions & 0 deletions docs/developer-docs/developer-tools/on-chain/ic-js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
keywords: [intermediate, ic-js, javascript, ic js, js]
---

import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";

# ic-js

<MarkdownChipRow labels={["Intermediate", "ic-js" ]} />

## Overview

`ic-js` is a collection of JavaScript libraries that can be used to interface with ICP. Each library can be used independently from one another, or a project can use all of the libraries together. The NNS dapp is an example demonstration of all `ic-js` libraries being used together.


## Dependencies

`ic-js` uses `@dfinity/agent` (agent-js) and `@dfinity/utils` as peer dependencies. It is recommended to have these packages available in your project as well.

You can install them using `npm`:

```
npm i @dfinity/agent @dfinity/candid @dfinity/principal @dfinity/utils
```


## Libraries


### Governance

- [nns](https://github.com/dfinity/ic-js/tree/main/packages/nns): Interface with the governance canisters of the Network Nervous System (NNS).

- [sns](https://github.com/dfinity/ic-js/tree/main/packages/sns): Interface with a Service Nervous System (SNS) project.

- [nns-proto](https://github.com/dfinity/ic-js/tree/main/packages/nns-proto): The protobuf source used by `nns-js` to support hardware wallets.


You can install these libraries with `npm`:

```
npm i @dfinity/nns
npm i @dfinity/sns
npm i @dfinity/nns-proto
```

### Tokens

- [cmc](https://github.com/dfinity/ic-js/tree/main/packages/cmc): Interface with the cycles minting canister (CMC).

- [ledger-icp](https://github.com/dfinity/ic-js/tree/main/packages/ledger-icp): Interface with the ICP ledger.

- [ledger-icrc](https://github.com/dfinity/ic-js/tree/main/packages/ledger-icrc): Interface with ICRC-compatible ledgers.

- [ckBTC](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc): Interface with ckBTC.

- [ckETH](https://github.com/dfinity/ic-js/tree/main/packages/cketh): Interface with ckETH.

You can install these libraries with `npm`:

```
npm i @dfinity/cmc
npm i @dfinity/ledger-icp
npm i @dfinity/ledger-icrc
npm i @dfinity/ckbtc
npm i @dfinity/cketh
```

### Management canister

- [ic-management](https://github.com/dfinity/ic-js/tree/main/packages/ic-management): Interface with the management canister.

You can install this library with `npm`:

```
npm i @dfinity/ic-management
```


### Utilities

- [utils](https://github.com/dfinity/ic-js/tree/main/packages/utils): A collection of utilities and constants.

You can install this library with `npm`:

```
npm i @dfinity/utils
```
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Learn more in the [Bitcoin integration technical overview](/docs/current/referen

- [Chain-key tokens](https://internetcomputer.org/how-it-works/chain-key-tokens/).

- [ckBTC](https://github.com/dfinity/ic-js/tree/main/packages/ckbtc) JavaScript library.

- [GitHub repository](https://github.com/dfinity/ic/tree/master/rs/bitcoin/ckbtc/minter).

- [Local development workflow](/docs/current/developer-docs/multi-chain/bitcoin/using-btc/local-development).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ ckETH has many of the same use-cases as ckBTC, such as:

- [ckETH transaction explorer](https://dashboard.internetcomputer.org/ethereum/transactions).

- [Github repository](https://github.com/dfinity/ic/blob/master/rs/ethereum/cketh/docs/cketh.adoc).
- [Github repository](https://github.com/dfinity/ic/blob/master/rs/ethereum/cketh/docs/cketh.adoc).

- [ckETH](https://github.com/dfinity/ic-js/tree/main/packages/cketh) JavaScript library.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def get_raw_rand() -> Async[RawRandResult]:
</AdornedTab>
</AdornedTabs>

You can also use the [ic-management](https://github.com/dfinity/ic-js/tree/main/packages/ic-management) JavaScript library to interact with the management canister.


## Typical workflows involving the management canister

The management canister offers a variety of endpoints that provide access to special features available on ICP. These can be grouped into a few main areas. Let's explore some of those.
Expand Down
6 changes: 2 additions & 4 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,8 @@ const sidebars = {
type: "category",
label: "On-chain libraries",
items: [
{
type: "doc",
id: "developer-docs/developer-tools/on-chain/cdks",
},
"developer-docs/developer-tools/on-chain/cdks",
"developer-docs/developer-tools/on-chain/ic-js",
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion submodules/internetidentity
Submodule internetidentity updated 41 files
+1 −1 .didc-release
+0 −25 .github/workflows/canister-tests.yml
+1 −1 .node-version
+62 −17 Cargo.lock
+3 −3 Cargo.toml
+8 −8 README.md
+0 −13 allowed_breaking_change.patch
+15 −14 demos/test-app/Cargo.lock
+2 −2 demos/test-app/Cargo.toml
+60 −15 demos/vc_issuer/Cargo.lock
+2 −2 demos/vc_issuer/Cargo.toml
+1 −1 dfx.json
+1 −1 docs/ii-spec.md
+16 −1 src/archive/src/main.rs
+ src/frontend/assets/icons/b3pay_logo.png
+ src/frontend/assets/icons/hamster_logo.png
+27 −0 src/frontend/assets/icons/pass_logo.svg
+20 −2 src/frontend/src/flows/dappsExplorer/dapps.json
+1 −1 src/internet_identity/src/anchor_management.rs
+1 −1 src/internet_identity/src/archive.rs
+2 −2 src/internet_identity/src/delegation.rs
+10 −6 src/internet_identity/src/http/metrics.rs
+17 −21 src/internet_identity/src/main.rs
+4 −4 src/internet_identity/src/state.rs
+9 −0 src/internet_identity/src/stats.rs
+4 −5 src/internet_identity/src/stats/activity_stats.rs
+0 −0 src/internet_identity/src/stats/activity_stats/activity_counter.rs
+1 −1 src/internet_identity/src/stats/activity_stats/activity_counter/active_anchor_counter.rs
+1 −1 src/internet_identity/src/stats/activity_stats/activity_counter/authn_method_counter.rs
+1 −1 src/internet_identity/src/stats/activity_stats/activity_counter/domain_active_anchor_counter.rs
+2 −2 src/internet_identity/src/stats/activity_stats/maintenance.rs
+4 −5 src/internet_identity/src/stats/event_stats.rs
+2 −4 src/internet_identity/src/stats/event_stats/event_aggregations.rs
+4 −6 src/internet_identity/src/stats/event_stats/event_aggregations/tests.rs
+6 −6 src/internet_identity/src/stats/event_stats/tests.rs
+13 −21 src/internet_identity/src/storage.rs
+4 −4 src/internet_identity/src/storage/storable_persistent_state.rs
+2 −2 src/internet_identity/src/storage/tests.rs
+56 −13 src/internet_identity/tests/integration/aggregation_stats.rs
+1 −0 src/internet_identity/tests/integration/http.rs
+40 −3 src/internet_identity_interface/src/archive/types.rs
2 changes: 1 addition & 1 deletion submodules/sdk
Submodule sdk updated 53 files
+39 −10 CHANGELOG.md
+634 −435 Cargo.lock
+4 −4 Cargo.toml
+5 −5 docs/cli-reference/dfx-canister.mdx
+4 −0 docs/cli-reference/dfx-envars.mdx
+6 −6 docs/cli-reference/dfx-identity.mdx
+17 −1 docs/cli-reference/dfx-info.mdx
+9 −2 docs/cli-reference/dfx-ledger.mdx
+10 −10 docs/dfx-json-schema.json
+2 −2 e2e/assets/wasm/identity/README.adoc
+2 −6 e2e/tests-dfx/assetscanister.bash
+3 −3 e2e/tests-dfx/build.bash
+5 −5 e2e/tests-dfx/create.bash
+1 −1 e2e/tests-dfx/deploy.bash
+15 −0 e2e/tests-dfx/info.bash
+5 −0 e2e/tests-dfx/ledger.bash
+1 −1 e2e/tests-dfx/rust.bash
+4 −4 e2e/tests-dfx/update_settings.bash
+23 −8 e2e/utils/_.bash
+3 −2 public/manifest.json
+66 −9 src/canisters/frontend/ic-asset/src/sync.rs
+2 −0 src/dfx-core/Cargo.toml
+11 −11 src/dfx-core/src/config/model/dfinity.rs
+53 −0 src/dfx-core/src/error/builder.rs
+1 −1 src/dfx-core/src/error/dfx_config.rs
+3 −0 src/dfx-core/src/error/identity/new_identity_manager.rs
+1 −0 src/dfx-core/src/error/mod.rs
+1 −1 src/dfx-core/src/error/root_key.rs
+2 −2 src/dfx-core/src/extension/manifest/extension.rs
+9 −0 src/dfx-core/src/identity/identity_manager.rs
+533 −0 src/dfx-core/src/interface/builder.rs
+44 −0 src/dfx-core/src/interface/dfx.rs
+4 −0 src/dfx-core/src/interface/mod.rs
+4 −0 src/dfx-core/src/lib.rs
+17 −1 src/dfx-core/src/network/root_key.rs
+1 −1 src/dfx/Cargo.toml
+3 −3 src/dfx/src/commands/canister/create.rs
+1 −1 src/dfx/src/commands/canister/info.rs
+1 −1 src/dfx/src/commands/canister/install.rs
+1 −1 src/dfx/src/commands/canister/status.rs
+2 −2 src/dfx/src/commands/canister/update_settings.rs
+14 −41 src/dfx/src/commands/deploy.rs
+2 −2 src/dfx/src/commands/identity/deploy_wallet.rs
+1 −1 src/dfx/src/commands/identity/new.rs
+20 −3 src/dfx/src/commands/info/mod.rs
+17 −8 src/dfx/src/commands/ledger/account_id.rs
+1 −1 src/dfx/src/lib/builders/custom.rs
+6 −2 src/dfx/src/lib/environment.rs
+2 −2 src/dfx/src/lib/ic_attributes/mod.rs
+4 −4 src/dfx/src/lib/models/canister.rs
+34 −0 src/dfx/src/lib/named_canister.rs
+1 −1 src/dfx/src/lib/operations/canister/deploy_canisters.rs
+2 −2 src/dfx/src/lib/root_key.rs

0 comments on commit 1858202

Please sign in to comment.