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

hydrajs-wallet

v0.0.23

Published

A toolkit for building HYDRA light wallets

Downloads

11

Readme

hydrajs-wallet

A toolkit for building HYDRA light wallets

This is a client-side wallet library that can generate private keys from a mnemonic, or import private keys from other HYDRA wallets.

It can sign transactions locally, and submit the raw transaction data to a remote HYDRA node. The blockchain data is provided by the Insight API (which powers https://explorer.hydrachain.org/), rather than the raw hydrad RPC calls.

This library makes it possible to run DApp without the users having to run a full HYDRA node.

Install

yarn add hydrajs-wallet

API

Examples

Create Mnemonic+Password Wallet

import { networks, generateMnemonic } from "hydrajs-wallet";

async function main() {
  const network = networks.testnet;
  const mnemonic = generateMnemonic();
  const password = "password";

  const wallet = network.fromMnemonic(mnemonic, password);

  console.log("mnemonic:", mnemonic);
  console.log("public address:", wallet.address);
  console.log("private key (WIF):", wallet.toWIF());
}

main().catch(err => console.log(err));

Example Output:

mnemonic: hold struggle ready lonely august napkin enforce retire pipe where avoid drip
public address: TLUHmrFGexxpyHwQphLpE1czZNFE5m1xmV
private key (WIF): cNQKccYYQyGX9G9Qxq2DJev9jHygbZpb2UG7EvUapbtDx5XhkhYE

Send Fund

This example restores a wallet from a private key (in WIF format), then sending value to another address.

The transaction is signed locally, and the transaction submitted to a remote API.

The currency unit used is satoshi. To convert HYDRA to satoshi you should multiply the amount you want with 1e8.

import { networks } from "hydrajs-wallet";

async function main() {
  // Use the test network. Or `networks.mainnet`
  const network = networks.testnet;

  const wif = "cU4ficvRNvR7jnbtczCWo5s9rB9Tdg1U4LkArVpGU6cKnDq7LFoP";
  const wallet = network.fromWIF(wif);

  console.log(wallet.address);

  const toAddr = "TS3ThpDn4HRH9we2hZUdF3F3uR7TTvpZ9v";
  // Sending 0.1 HYDRA
  const sendtx = await wallet.send(toAddr, 0.01 * 1e8);
  console.log("sendtx", sendtx);
}

main().catch(err => console.log(err));

Send To Contract

Let's burn some money using the Burn contract:

pragma solidity ^0.4.18;

contract Burn {
  uint256 public totalburned;
  event DidBurn(address burnerAddress, uint256 burnedAmount);

  function burnbabyburn() public payable {
    totalburned = msg.value;
    DidBurn(msg.sender, msg.value);
  }
}

The ABI encoding for the burnbabyburn() invokation is e179b912. We'll burn 0.05 HYDRA, expressed in unit of satoshi.

import { networks } from "hydrajs-wallet";

async function main() {
  const network = networks.testnet;

  const privateKey = "cU4ficvRNvR7jnbtczCWo5s9rB9Tdg1U4LkArVpGU6cKnDq7LFoP";

  const wallet = network.fromWIF(privateKey);

  const contractAddress = "b10071ee33512ce8a0c06ecbc14a5f585a27a3e2";
  const encodedData = "e179b912"; // burnbabyburn()

  const tx = await wallet.contractSend(contractAddress, encodedData, {
    amount: 0.05 * 1e8 // 0.05 HYDRA in satoshi
  });

  console.log(tx);
}

main().catch(err => console.log(err));

Networks

Two networks are predefined:

import { networks } from "hydrajs-wallet";

// Main Network
networks.mainnet;

// Test Network
networks.testnet;

fromPrivateKey

Alias for fromWIF.

fromWIF

fromWIF constructs a wallet from private key (in WIF format).

Suppose you want to import the public address Tg3HYD8c4bAVLeEzA9t3Ken3Y3Mni1HZSS. Use hydra-cli to dump the private key from wallet:

hydra-cli dumpprivkey Tg3HYD8c4bAVLeEzA9t3Ken3Y3Mni1HZSS

cVHzWuEKUxoRKba9ySZFqUKZ9G5W8NkzthRcPaB65amUJs95RM3d
const network = networks.testnet;

const privateKey = "cVEwiJ5NMTdnkW4ZW2ykUopawtLPXQWtPDmvpTh5jmXYMtg8itAz";

const wallet = network.fromWIF(privateKey);
console.log("public address:", wallet.address);

Output:

public address: TWAnfBnRNhZBqtgSdgHjSfS2D5Jawmafra

fromMnemonic

fromMnemonic constructs a wallet from mnemonic. User can optionally specify a password to add to the mnemonic entropy.

const network = networks.testnet;
const mnemonic =
  "hold struggle ready lonely august napkin enforce retire pipe where avoid drip";
const password = "password";

const wallet = network.fromMnemonic(mnemonic, password);

console.log("public address:", wallet.address);
console.log("private key (WIF):", wallet.toWIF());

Example Output:

public address: TLUHmrFGexxpyHwQphLpE1czZNFE5m1xmV
private key (WIF): cNQKccYYQyGX9G9Qxq2DJev9jHygbZpb2UG7EvUapbtDx5XhkhYE