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

harmony-ethers-sdk

v0.0.5

Published

```ts import { Block, BlockWithTransactions, CXTransactionReceipt, StakingTransactionResponse, TransactionReceipt, TransactionResponse, } from "../src/types"; import { ApiHarmonyProvider } from "../src/provider";

Downloads

6

Readme

Harmony Ethers.js Wrapper

How to use provider to query Harmony chain

import {
  Block,
  BlockWithTransactions,
  CXTransactionReceipt,
  StakingTransactionResponse,
  TransactionReceipt,
  TransactionResponse,
} from "../src/types";
import { ApiHarmonyProvider } from "../src/provider";

// provider auto detects shard
const provider = new ApiHarmonyProvider("https://api.s0.b.hmny.io");
// to get block with harmony properties
const block: Block = await provider.getBlock(blockNumber || blockHash);
// to get block with transactions including staking transactions
const blockWithTransaction: BlockWithTransactions = await provider.getBlockWithTransactions(blockNumber || blockHash);

// get transaction / cx transaction
const tx: TransactionResponse = provider.getTransaction(txHash);
// get staking transaction
const sTx: StakingTransactionResponse = provider.getStakingTransaction(txHash);

// to get staking transaction recipt
const txReceipt: TransactionReceipt = provider.getTransactionReceipt(txHash);

// to get Cross Shard Receipt
const cTxReceipt: CXTransactionReceipt = provider.getCXTransactionReceipt(txHash);

How to use wallet to sign and send transaction and cross shard transactions

import { ApiHarmonyProvider } from "../src/provider";
import { ExternallyOwnedAccount } from "@ethersproject/abstract-signer";
import { parseEther } from "@ethersproject/units";
import Wallet from "../src/wallet";

const account: ExternallyOwnedAccount = {
  address: "0x",
  privateKey: "0x",
};

const provider = new ApiHarmonyProvider("https://api.s0.b.hmny.io");
const wallet = new Wallet(account, provider);
await provider.ready;

// transaction
const tx = await wallet.sendTransaction({
  to: "one..." || "0x...",
  value: parseEther("10"),
});

// cross shard transaction
const tx = await wallet.sendTransaction({
  to: "one..." || "0x...",
  value: parseEther("10"),
  toShardID: 1,
});

How to use wallet to sign and send staking transaction

import { ExternallyOwnedAccount } from "@ethersproject/abstract-signer";
import { parseEther } from "@ethersproject/units";
import { ApiHarmonyProvider } from "../src/provider";
import { Directive, StakingTransactionRequest } from "../src/types";
import Wallet from "../src/wallet";

const account: ExternallyOwnedAccount = {
  address: "0x",
  privateKey: "0x",
};

const provider = new ApiHarmonyProvider("https://api.s0.b.hmny.io");
const wallet = new Wallet(account, provider);
await provider.ready;

// Create Validator
const createValidator: StakingTransactionRequest = {
  type: Directive.CreateValidator,
  msg: {
    validatorAddress: wallet.address,
    amount: parseEther("10000"),
    commissionRates: {
      rate: "0.1",
      maxRate: "0.1",
      maxChangeRate: "0.01",
    },
    maxTotalDelegation: parseEther("1000000"),
    minSelfDelegation: parseEther("10000"),
    slotPubKeys: [],
    slotKeySigs: [],
    description: {
      name: "Test",
      identity: "Test",
      details: "Testing",
      securityContact: "[email protected]",
      website: "test.com",
    },
  },
};

const createValidatorRes = await wallet.sendStakingTransaction(createValidator);

// Edit Validator
const editValidator: StakingTransactionRequest = {
  type: Directive.EditValidator,
  msg: {
    validatorAddress: wallet.address,
    commissionRate: "0.09",
    description: {
      name: "Test",
      identity: "test",
      details: "",
      securityContact: "[email protected]",
      website: "",
    },
    active: false,
  },
};

const editValidatorRes = await wallet.sendStakingTransaction(editValidator);

// Delegate
const delegate: StakingTransactionRequest = {
  type: Directive.Delegate,
  msg: {
    delegatorAddress: wallet.address,
    validatorAddress: "one1xjanr7lgulc0fqyc8dmfp6jfwuje2d94xfnzyd",
    amount: parseEther("1000"),
  },
};

const delegateRes = await wallet.sendStakingTransaction(delegate);

// Undelegate
const undelegate: StakingTransactionRequest = {
  type: Directive.Undelegate,
  msg: {
    delegatorAddress: wallet.address,
    validatorAddress: "one1xjanr7lgulc0fqyc8dmfp6jfwuje2d94xfnzyd",
    amount: parseEther("1000"),
  },
};

const undelegateRes = await wallet.sendStakingTransaction(undelegate);

// Collect Rewards
const collectRewards: StakingTransactionRequest = {
  type: Directive.CollectRewards,
  msg: {
    delegatorAddress: wallet.address,
  },
};

const collectRewardsRes = await wallet.sendStakingTransaction(collectRewards);

HarmonyAddress

same api as harmony js sdk

const address = new HarmonyAddress("one..." || "0x...");

HarmonyNetwork

interface ShardStructure {
  current: boolean;
  http: string;
  shardID: number;
  ws: string;
}

interface HarmonyNetwork extends Network {
  shardID: number;
  shardingStructure?: ShardStructure[];
}

HarmonyProvider

export interface HarmonyProvider extends BaseProvider {
  network: HarmonyNetwork;

  // Execution
  sendTransaction(signedTransaction: string | Promise<string>): Promise<TransactionResponse>;
  sendStakingTransaction(signedTransaction: string | Promise<string>): Promise<StakingTransactionResponse>;

  call(transaction: Deferrable<TransactionRequest>, blockTag?: BlockTag | Promise<BlockTag>): Promise<string>;
  estimateGas(transaction: Deferrable<TransactionRequest>): Promise<BigNumber>;

  // Queries
  getBlock(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>): Promise<Block>;
  getBlockWithTransactions(blockHashOrBlockTag: BlockTag | string | Promise<BlockTag | string>): Promise<BlockWithTransactions>;

  getTransaction(transactionHash: string): Promise<TransactionResponse>;
  getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
  getCXTransactionReceipt(transactionHash: string): Promise<CXTransactionReceipt>;

  getStakingTransaction(transactionHash: string): Promise<StakingTransactionResponse>;

  getCirculatingSupply(): Promise<BigNumber>;
  getTotalSupply(): Promise<BigNumber>;

  getEpoch(): Promise<number>;
  getEpochLastBlock(epoch: number): Promise<number>;

  getLeader(): Promise<string>;

  getValidatorsAddresses(): Promise<Array<string>>;
  getActiveValidatorsAddresses(): Promise<Array<string>>;

  getDelegationsByValidator(validatorAddress: string): Promise<Array<Delegation>>;
  getDelegationsByDelegator(delegatorAddress: string): Promise<Array<Delegation>>;
}