Skip to content

Commit

Permalink
docs: update outdated nns-js README
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Nov 6, 2023
1 parent 014e017 commit b88e386
Showing 1 changed file with 12 additions and 24 deletions.
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/ledger-icrc";
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();
```

## Features
Expand Down

0 comments on commit b88e386

Please sign in to comment.