Skip to content

Commit

Permalink
docs: governance canister local snippet (#487)
Browse files Browse the repository at this point in the history
# Motivation

I followed the README to setup a sample script and I have to say that an
example of local usages would have been useful.
Therefore providing this PR to add it.
  • Loading branch information
peterpeterparker authored Nov 28, 2023
1 parent 55e5f64 commit 33014d6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/nns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ const { listNeurons } = GovernanceCanister.create({
const myNeurons = await listNeurons({ certified: false });
```

To execute this on a local environment, you will need to fetch the root key when initializing the agent. Additionally, you might need to adapt the port. The following snippet also demonstrates how you can inline a canister ID as well.

```typescript
import { GovernanceCanister } from "@dfinity/nns";
import { createAgent } from "@dfinity/utils";
import { Principal } from "@dfinity/principal";

const agent = await createAgent({
identity,
host: "http://localhost:8000",
fetchRootKey: true,
});

const { listNeurons } = GovernanceCanister.create({
agent,
canisterId: Principal.fromText("rrkah-fqaaa-aaaaa-aaaaq-cai"),
});

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

## Features

`nns-js` implements following features:
Expand Down

0 comments on commit 33014d6

Please sign in to comment.