npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

codechain-stakeholder-sdk

v2.0.0

Published

A JavaScript implementation for CodeChain stake token related custom actions and custom transactions

Downloads

19

Readme

CodeChain Stakeholder SDK

A JavaScript implementation for CodeChain stake token related custom actions and custom transactions

Features

It adds the following features to CodeChain SDK for JavaScript:

  • Query staking states
  • Call staking related RPC
  • Create staking transactions

API Examples

You first need to install the package.

# npm
npm install codechain-stakeholder-sdk

# yarn
yarn add codechain-stakeholder-sdk

Then prepare SDK instance as usual.

import { SDK } from "codechain-sdk";
const sdk = new SDK({
  server: "http://localhost:8080",
  networkId: "tc"
});

Now, you are prepared to use stakeholder-sdk-js

Query staking states

These functions can have an optional block number parameter at the end.

Get the list of stakeholders

import { getCCSHolders } from "codechain-stakeholder-sdk";

const holders = await getCCSHolders(sdk);
// holders: PlatformAddress[]

Get the quantity of undelegated stake token of a stakeholder

import { getUndelegatedCCS } from "codechain-stakeholder-sdk";

const balance = await getUndelegatedCCS(
  sdk,
  "tccq9h7vnl68frvqapzv3tujrxtxtwqdnxw6yamrrgd"
);
// balance: U64

Get the list of delegations that a stakeholder delegated to delegatees

import { getDelegations } from "codechain-stakeholder-sdk";

const delegations = await getDelegations(
  sdk,
  "tccq9h7vnl68frvqapzv3tujrxtxtwqdnxw6yamrrgd"
);
for (const { delegatee, quantity } of delegations) {
  // delegatee: PlatformAddress
  // quantity: U64
}

Get the list of validator candidates

import { getCandidates } from "codechain-stakeholder-sdk";

const candidates = await getCandidates(sdk);
for (const { pubkey, deposit, nominationEndsAt, metadata } of candidates) {
  // pubkey: H512
  // deposit: U64
  // nominationEndsAt: U64
  // metadata: Buffer
}

Get the list of jailed accounts

import { getJailed } from "codechain-stakeholder-sdk";

const prisoners = await getJailed(sdk);
for (const { address, deposit, custodyUntil, releasedAt } of prisoners) {
  // address: PlatformAddress
  // deposit: U64
  // custodyUntil: U64
  // releasedAt: U64
}

Get the list of banned accounts

import { getBanned } from "codechain-stakeholder-sdk";

const banned = await getBanned(sdk);
// banned: PlatformAddress[]

Get intermediate rewards

import { getIntermediateRewards } from "codechain-stakeholder-sdk";

const { previous, current } = await getIntermediateRewards(sdk);
// previous, current: { address: PlatformAddress, quantity: U64 }[]

Get the list of current validators

import { getValidators } from "codechain-stakeholder-sdk";

const validators = await getValidators(sdk);
for (const { weight, delegation, deposit, pubkey } of validators) {
  // weight: U64
  // delegation: U64
  // deposit: U64
  // pubkey: H512
}

RPCs to query staking status

TermMetadata

import { getTermMetadata } from "codechain-stakeholder-sdk";

const { lastTermFinishedBlockNumber, currentTermId } = await getTermMetadata(
  sdk
);

Create staking transactions

Transfer stake tokens

import { createTransferCCSTransaction } from "codechain-stakeholder-sdk";

// Transfer 100 tokens to tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f
const tx = createTransferCCSTransaction(
  sdk,
  "tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f",
  100
)
const signedTx = .sign({ secret: "...", seq: "...", fee: "..." });
const txhash = await sdk.rpc.chain.sendSignedTransaction(signedTx);

Delegate stake tokens

import { createDelegateCCSTransaction } from "codechain-stakeholder-sdk";

// Delegate 100 tokens to tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f
const tx = createDelegateCCSTransaction(
  sdk,
  "tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f",
  100
);
const signedTx = tx.sign({ secret: "...", seq: "...", fee: "..." });
const txhash = await sdk.rpc.chain.sendSignedTransaction(signedTx);

Revoke stake tokens

import { createRevokeTransaction } from "codechain-stakeholder-sdk";

// Revoke 100 tokens delegated to tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f
const tx = createRevokeTransaction(
  sdk,
  "tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f",
  100
);
const signedTx = tx.sign({ secret: "...", seq: "...", fee: "..." });
const txhash = await sdk.rpc.chain.sendSignedTransaction(signedTx);

Redelegate stake tokens

import { createRedelegateTransaction } from "codechain-stakeholder-sdk";

// Redelegate 100 tokens to "tccq9qvruafmf9vegjhkl0ruunkwp0d4lc8fgxknzh5"
// which was delegated to "tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f".
const tx = createRedelegateTransaction(
  sdk,
  "tccq94guhkrfndnehnca06dlkxcfuq0gdlamvw9ga4f",
  "tccq9qvruafmf9vegjhkl0ruunkwp0d4lc8fgxknzh5",
  100
);
const signedTx = tx.sign({ secret: "...", seq: "...", fee: "..." });
const txhash = await sdk.rpc.chain.sendSignedTransaction(signedTx);

Self-nominate

import { createSelfNominateTransaction } from "codechain-stakeholder-sdk";

// Self-nominate with 1000 CCC and metadata
const tx = createSelfNominateTransaction(sdk, 1000, "some-metadata");
const signedTx = tx.sign({ secret: "...", seq: "...", fee: "..." });
const txhash = await sdk.rpc.chain.sendSignedTransaction(signedTx);

Report double vote

import { createReportDoubleVoteTransaction } from "codechain-stakeholder-sdk";

// Report double vote message
const tx = createReportDoubleVoteTransaction(sdk, message1, message2);
const signedTx = tx.sign({ secret: "...", seq: "...", fee: "..." });
const txhash = await sdk.rpc.chain.sendSignedTransaction(signedTx);