Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update outdated nns-js README #458

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions packages/nns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ A library for interfacing with the Internet Computer's Network Nervous System.
- [Installation](#installation)
- [Usage](#usage)
- [Features](#features)
- [AccountIdentifier](#factory-accountidentifier)
- [SubAccount](#factory-subaccount)
- [GenesisTokenCanister](#factory-genesistokencanister)
- [ICP](#factory-icp)
- [LedgerCanister](#factory-ledgercanister)
- [GovernanceCanister](#factory-governancecanister)
- [SnsWasmCanister](#factory-snswasmcanister)

## Installation

Expand All @@ -33,28 +26,23 @@ npm i @dfinity/agent @dfinity/candid @dfinity/principal @dfinity/utils @dfinity/

## Usage

Most features are provided through the use of classes. e.g. querying the `ledger` for an account balance in a NodeJS context can be developed as following:
Most features are provided through the use of classes. For example, querying the list of neurons controlled by the caller with the `governance` canister:

```ts
import { AccountIdentifier, LedgerCanister } from "@dfinity/nns";
import { GovernanceCanister } from "@dfinity/nns";
import { createAgent } from "@dfinity/utils";

// If not running in browser, add polyfill of `window.fetch` for agent-js to work.
import fetch from "cross-fetch";
global.fetch = fetch;
const agent = await createAgent({
identity,
host: HOST,
});

const main = async () => {
const ledger = LedgerCanister.create();
const { listNeurons } = GovernanceCanister.create({
agent,
canisterId: MY_GOVERNANCE_CANISTER_ID,
});

const accountIdentifier = AccountIdentifier.fromHex(
"efa01544f509c56dd85449edf2381244a48fad1ede5183836229c00ab00d52df",
);

const balance = await ledger.accountBalance({ accountIdentifier });

console.log(`Balance: ${balance}`);
};

await main();
const myNeurons = await listNeurons({ certified: false });
```

## Features
Expand Down
Loading