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

ergonaddrjs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ergonaddrjs

Ergon address format support for Node.js and web browsers.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
44
increased by266.67%
Maintainers
1
Weekly downloads
 
Created
Source

ergonaddr.js: The Ergon address format for Node.js and web browsers.

NPM

JavaScript implementation for CashAddr address format for Ergon.

Compliant with the original CashAddr specification which improves upon BIP 173.

Note: This is a JavaScript implementation of the CashAddr format specification. If you are looking for a general purpose Bitcoin Cash address translation library, check out the easy-to-use and well-tested BchAddr.js.

Installation

Using NPM

$ npm install ergonaddrjs

Manually

You may also download the distribution file manually and place it within your third-party scripts directory: dist/ergonaddrjs-1.0.0.min.js.

Usage

Convert a bitcoincash: prefixed address to an ergon: prefixed address

In Node.js

const ergonaddr = require("ergonaddrjs");
const bitcoincashAddress =
  "bitcoincash:qpadrekpz6gjd8w0zfedmtqyld0r2j4qmuj6vnmhp6";
const { prefix, type, hash } = ergonaddr.decode(bitcoincashAddress);
console.log(prefix); // 'bitcoincash'
console.log(type); // 'P2PKH'
console.log(hash); // Uint8Array [ 118, 160, ..., 115 ]
console.log(cashaddr.encode("ergon", type, hash));
// 'ergon:qpadrekpz6gjd8w0zfedmtqyld0r2j4qmunpeyresh'

React

import cashaddr from "ergonaddrjs";

function convertBitcoincashToErgon(bitcoincashAddress) {
  /* NOTE 
  This function assumes input parameter 'bitcoincashAddress' is a valid bitcoincash: address
  cashaddr.decode() will throw an error if 'bitcoincashAddress' lacks a prefix 
  */
  const { prefix, type, hash } = cashaddr.decode(bitcoincashAddress);
  const ergonAddress = cashaddr.encode("ergon", type, hash);
  return ergonAddress;
}

Browser

<html>
  <head>
    <script src="https://unpkg.com/ergonaddrjs@1.0.0/dist/cashaddrjs-1.0.0.min.js"></script>
  </head>
  <body>
    <script>
      function convertBitcoincashToErgon(bitcoincashAddress) {
        /* NOTE 
    This function assumes input parameter 'bitcoincashAddress' is a valid bitcoincash: address
    cashaddr.decode() will throw an error if 'bitcoincashAddress' lacks a prefix 
    */
        const { prefix, type, hash } = ergonaddr.decode(bitcoincashAddress);
        const ergonAddress = ergonaddr.encode("ergon", type, hash);
        return ergonAddress;
      }
      const ergonAddress = convertBitcoincashToErgon(
        "bitcoincash:qpadrekpz6gjd8w0zfedmtqyld0r2j4qmuj6vnmhp6"
      );
      console.log(ergonAddress);
      // ergon:qpadrekpz6gjd8w0zfedmtqyld0r2j4qmunpeyresh
    </script>
  </body>
</html>
Script Tag

You may include a script tag in your HTML and the ergonaddr module will be defined globally on subsequent scripts.

<html>
  <head>
    ...
    <script src="https://unpkg.com/ergonaddrjs@1.0.0/dist/cashaddrjs-1.0.0.min.js"></script>
  </head>
  ...
</html>
jsFiddle

https://jsfiddle.net/zghd6c2y/

Keywords

FAQs

Package last updated on 24 Sep 2021

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