Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dfinity/nns

Package Overview
Dependencies
Maintainers
0
Versions
1060
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dfinity/nns

A library for interfacing with the Internet Computer's Network Nervous System.

  • 8.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
increased by57.16%
Maintainers
0
Weekly downloads
 
Created
Source

nns-js

A library for interfacing with the Internet Computer's Network Nervous System.

npm version GitHub license

Table of contents

Installation

You can use nns-js by installing it in your project.

npm i @dfinity/nns

The bundle needs peer dependencies, be sure that following resources are available in your project as well.

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

Usage

Most features are provided through the use of classes. For example, querying the list of neurons controlled by the caller with the governance canister:

import { GovernanceCanister } from "@dfinity/nns";
import { createAgent } from "@dfinity/utils";

const agent = await createAgent({
  identity,
  host: HOST,
});

const { listNeurons } = GovernanceCanister.create({
  agent,
  canisterId: MY_GOVERNANCE_CANISTER_ID,
});

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.

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

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:

:toolbox: Functions

:gear: ineligibleNeurons

Filter the neurons that are ineligible to vote to a proposal.

This feature needs the ballots of the proposal to contains accurate data. If the proposal has settled, as the ballots of the proposal are emptied for archive purpose, the function might return a list of ineligible neurons that are actually neurons that have not voted but would have been eligible.

Long story short, check the status of the proposal before using this function.

FunctionType
ineligibleNeurons({ neurons, proposal, }: { neurons: NeuronInfo[]; proposal: ProposalInfo; }) => NeuronInfo[]

Parameters:

  • params.neurons: The neurons to filter.
  • params.proposal: The proposal to match against the selected neurons.

:link: Source

:gear: votableNeurons

Filter the neurons that can vote for a proposal - i.e. the neurons that have not voted yet and are eligible

FunctionType
votableNeurons({ neurons, proposal, }: { neurons: NeuronInfo[]; proposal: ProposalInfo; }) => NeuronInfo[]

Parameters:

  • params.neurons: The neurons to filter.
  • params.proposal: The proposal to match against the selected neurons.

:link: Source

:gear: votedNeurons

Filter the neurons that have voted for a proposal.

FunctionType
votedNeurons({ neurons, proposal, }: { neurons: NeuronInfo[]; proposal: ProposalInfo; }) => NeuronInfo[]

Parameters:

  • params.neurons: The neurons to filter.
  • params.proposal: The proposal for which some neurons might have already voted.

:link: Source

:gear: memoToNeuronSubaccount
FunctionType
memoToNeuronSubaccount({ controller, memo, }: { controller: Principal; memo: bigint; }) => SubAccount

:link: Source

:gear: memoToNeuronAccountIdentifier
FunctionType
memoToNeuronAccountIdentifier({ controller, memo, governanceCanisterId, }: { controller: Principal; memo: bigint; governanceCanisterId: Principal; }) => AccountIdentifier

:link: Source

:factory: GenesisTokenCanister

:link: Source

Methods
:gear: create
MethodType
create(options?: CanisterOptions<_SERVICE>) => GenesisTokenCanister

:link: Source

:gear: claimNeurons
MethodType
claimNeurons({ hexPubKey, }: { hexPubKey: string; }) => Promise<bigint[]>

:link: Source

:factory: GovernanceCanister

:link: Source

Methods
:gear: create
MethodType
create(options?: GovernanceCanisterOptions) => GovernanceCanister

:link: Source

:gear: listNeurons

Returns the list of neurons controlled by the caller.

If an array of neuron IDs is provided, precisely those neurons will be fetched.

If certified is true, the request is fetched as an update call, otherwise it is fetched using a query call.

The backend treats includeEmptyNeurons as true if absent.

MethodType
listNeurons({ certified, neuronIds, includeEmptyNeurons, includePublicNeurons, }: { certified: boolean; neuronIds?: bigint[] or undefined; includeEmptyNeurons?: boolean or undefined; includePublicNeurons?: boolean or undefined; }) => Promise<NeuronInfo[]>

:link: Source

:gear: listKnownNeurons

Returns the list of neurons who have been approved by the community to appear as the default followee options.

If certified is true, the request is fetched as an update call, otherwise it is fetched using a query call.

MethodType
listKnownNeurons(certified?: boolean) => Promise<KnownNeuron[]>

:link: Source

:gear: getLastestRewardEvent

Returns the latest reward event.

If certified is true, the request is fetched as an update call, otherwise it's fetched using a query call.

MethodType
getLastestRewardEvent(certified?: boolean) => Promise<RewardEvent>

:link: Source

:gear: listProposals

Returns the list of proposals made for the community to vote on, paginated and filtered by the request.

If certified is true (default), the request is fetched as an update call, otherwise it is fetched using a query call.

MethodType
listProposals({ request, certified, }: { request: ListProposalsRequest; certified?: boolean or undefined; }) => Promise<ListProposalsResponse>

Parameters:

  • request: the options to list the proposals (limit number of results, topics to search for, etc.)
  • certified: query or update calls

:link: Source

:gear: stakeNeuron
MethodType
stakeNeuron({ stake, principal, fromSubAccount, ledgerCanister, createdAt, fee, }: { stake: bigint; principal: Principal; fromSubAccount?: number[] or undefined; ledgerCanister: LedgerCanister; createdAt?: bigint or undefined; fee?: bigint or undefined; }) => Promise<...>

:link: Source

:gear: increaseDissolveDelay

Increases dissolve delay of a neuron

MethodType
increaseDissolveDelay({ neuronId, additionalDissolveDelaySeconds, }: { neuronId: bigint; additionalDissolveDelaySeconds: number; }) => Promise<void>

:link: Source

:gear: setDissolveDelay

Sets dissolve delay of a neuron. The new date is now + dissolveDelaySeconds.

MethodType
setDissolveDelay({ neuronId, dissolveDelaySeconds, }: { neuronId: bigint; dissolveDelaySeconds: number; }) => Promise<void>

:link: Source

:gear: startDissolving

Start dissolving process of a neuron

MethodType
startDissolving(neuronId: bigint) => Promise<void>

:link: Source

:gear: stopDissolving

Stop dissolving process of a neuron

MethodType
stopDissolving(neuronId: bigint) => Promise<void>

:link: Source

:gear: joinCommunityFund

Neuron joins the community fund

MethodType
joinCommunityFund(neuronId: bigint) => Promise<void>

:link: Source

:gear: autoStakeMaturity

Changes auto-stake maturity for this Neuron. While on, auto-stake maturity will cause all the maturity generated by voting rewards to this neuron to be automatically staked and contribute to the voting power of the neuron.

MethodType
autoStakeMaturity(params: { neuronId: bigint; autoStake: boolean; }) => Promise<void>

Parameters:

  • neuronId: The id of the neuron for which to request a change of the auto stake feature
  • autoStake: true to enable the auto-stake maturity for this neuron, false to turn it off

:link: Source

:gear: leaveCommunityFund

Neuron leaves the community fund

MethodType
leaveCommunityFund(neuronId: bigint) => Promise<void>

:link: Source

:gear: setVisibility

Set visibility of a neuron

MethodType
setVisibility(neuronId: bigint, visibility: NeuronVisibility) => Promise<void>

:link: Source

:gear: setNodeProviderAccount

Sets node provider reward account. Where the reward is paid to.

MethodType
setNodeProviderAccount(accountIdentifier: string) => Promise<void>

:link: Source

:gear: mergeNeurons

Merge two neurons

MethodType
mergeNeurons(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise<void>

:link: Source

:gear: simulateMergeNeurons

Simulate merging two neurons

MethodType
simulateMergeNeurons(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise<NeuronInfo>

:link: Source

:gear: splitNeuron

Splits a neuron creating a new one

MethodType
splitNeuron({ neuronId, amount, }: { neuronId: bigint; amount: bigint; }) => Promise<bigint>

:link: Source

:gear: getProposal

Returns single proposal info

If certified is true (default), the request is fetched as an update call, otherwise it is fetched using a query call.

MethodType
getProposal({ proposalId, certified, }: { proposalId: bigint; certified?: boolean or undefined; }) => Promise<ProposalInfo or undefined>

:link: Source

:gear: makeProposal

Create new proposal

MethodType
makeProposal(request: MakeProposalRequest) => Promise<bigint or undefined>

:link: Source

:gear: registerVote

Registers vote for a proposal from the neuron passed.

MethodType
registerVote({ neuronId, vote, proposalId, }: { neuronId: bigint; vote: Vote; proposalId: bigint; }) => Promise<void>

:link: Source

:gear: setFollowees

Edit neuron followees per topic

MethodType
setFollowees(followRequest: FollowRequest) => Promise<void>

:link: Source

:gear: disburse

Disburse neuron on Account

MethodType
disburse({ neuronId, toAccountId, amount, }: { neuronId: bigint; toAccountId?: string or undefined; amount?: bigint or undefined; }) => Promise<void>

:link: Source

:gear: mergeMaturity

Merge Maturity of a neuron

MethodType
mergeMaturity({ neuronId, percentageToMerge, }: { neuronId: bigint; percentageToMerge: number; }) => Promise<void>

:link: Source

:gear: stakeMaturity

Stake the maturity of a neuron.

MethodType
stakeMaturity({ neuronId, percentageToStake, }: { neuronId: bigint; percentageToStake?: number or undefined; }) => Promise<void>

Parameters:

  • neuronId: The id of the neuron for which to stake the maturity
  • percentageToStake: Optional. Percentage of the current maturity to stake. If not provided, all of the neuron's current maturity will be staked.

:link: Source

:gear: spawnNeuron

Merge Maturity of a neuron

MethodType
spawnNeuron({ neuronId, percentageToSpawn, newController, nonce, }: { neuronId: bigint; percentageToSpawn?: number or undefined; newController?: Principal or undefined; nonce?: bigint or undefined; }) => Promise<bigint>

:link: Source

:gear: addHotkey

Add hotkey to neuron

MethodType
addHotkey({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise<void>

:link: Source

:gear: removeHotkey

Remove hotkey to neuron

MethodType
removeHotkey({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise<void>

:link: Source

:gear: claimOrRefreshNeuronFromAccount

Gets the NeuronID of a newly created neuron.

MethodType
claimOrRefreshNeuronFromAccount({ memo, controller, }: { memo: bigint; controller?: Principal or undefined; }) => Promise<bigint or undefined>

:link: Source

:gear: claimOrRefreshNeuron

Refreshes neuron and returns neuronId when successful Uses query call only.

MethodType
claimOrRefreshNeuron(request: ClaimOrRefreshNeuronRequest) => Promise<bigint or undefined>

:link: Source

:gear: getNeuron

Return the data of the neuron provided as id.

MethodType
getNeuron({ certified, neuronId, }: { certified: boolean; neuronId: bigint; }) => Promise<NeuronInfo or undefined>

:link: Source

:factory: SnsWasmCanister

:link: Source

Methods
:gear: create
MethodType
create(options?: CanisterOptions<_SERVICE>) => SnsWasmCanister

:link: Source

:gear: listSnses
MethodType
listSnses({ certified, }: { certified?: boolean or undefined; }) => Promise<DeployedSns[]>

:link: Source

Keywords

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc