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

nadcab-labs-crypto-api

v1.0.6

Published

A unified JavaScript library to interact with Ethereum-compatible blockchains and Tron using a simplified API.

Downloads

30

Readme

Nadcab Labs Crypto API

Nadcab Labs Crypto API is a unified JavaScript library designed to simplify the interaction with multiple blockchain networks, including Ethereum-compatible blockchains (Ethereum, Binance Smart Chain, Polygon) and Tron. By combining the capabilities of web3 and tronweb into a single, cohesive API—called nc3.js—this library provides a streamlined and consistent interface for developers to work with these diverse blockchain ecosystems.

What is Crypto API?

A Crypto API is a set of programming interfaces and tools that allow developers to interact with blockchain networks and cryptocurrencies programmatically. It provides the necessary functions to perform blockchain operations such as generating wallet addresses, sending and receiving transactions, checking balances, and interacting with smart contracts.

Installation and Usage

To use the Nadcab Labs Crypto API, you need to install it via npm. Run the following command in your project directory:

npm install nadcab-labs-crypto-api

API Key Creation

If the Nadcab Labs Crypto API requires an API key to interact with blockchain networks or third-party services, follow these steps to create and use an API key:

  • Ethereum, BSC, and Polygon (EVM-Compatible Chains):

    • Sign up for an account with a blockchain node provider like Infura, Alchemy, or QuickNode.
    • Create a new project in the provider's dashboard.
    • Generate an API key for your project. This key will be used to interact with the blockchain network.
    • Copy the generated API key and use it as the providerUrl when initializing NC3 for Ethereum, BSC, or Polygon:
     const nc3Ethereum = new NC3('ethereum', 'https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
  • Tron:

    • Use TronGrid or any other Tron-compatible provider.

    • Sign up and create a new project to generate an API key.

    • Use the API key in the providerUrl when initializing NC3 for Tron:

      const nc3Tron = new NC3('tron', 'https://api.trongrid.io/YOUR_TRONGRID_API_KEY');

Create Address

To generate a blockchain address for different supported networks using the Nadcab Labs Crypto API:

  • Ethereum, BSC, and Polygon (EVM Chains):

    • Provide a private key to generate an address:
     const NC3 = require('nadcab-labs-crypto-api');
    
     # Initialize for Ethereum
     const nc3Ethereum = new NC3('ethereum', 'https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
    
     # Generate an Ethereum address using a private key
     const ethAddress = nc3Ethereum.generateAddress('your-private-key');
     console.log('Ethereum Address:', ethAddress);
  • Tron:

    • Simply call the method to generate a new address:

      # Initialize for Tron
      const nc3Tron = new NC3('tron', 'https://api.trongrid.io');
      
      # Generate a Tron address
      const tronAddress = nc3Tron.generateAddress();
      console.log('Tron Address:', tronAddress);

Send Transaction

To send a transaction on different supported blockchains:

  • Ethereum, BSC, and Polygon (EVM Chains):

    • Provide the necessary transaction details:

      nc3Ethereum.sendTransaction({
        from: 'your-eth-address',
        to: 'recipient-eth-address',
        value: nc3Ethereum.web3.utils.toWei('0.01', 'ether'), # Send 0.01 ETH
        gas: 21000,
        gasPrice: nc3Ethereum.web3.utils.toWei('20', 'gwei'), # Gas price in Gwei
      }).then((receipt) => {
        console.log('Ethereum Transaction Receipt:', receipt);
      }).catch(console.error);
  • Tron:

    • Use similar transaction details for Tron:

      nc3Tron.sendTransaction({
        from: 'your-tron-address',
        to: 'recipient-tron-address',
        amount: 100, # Amount in TRX
      }).then((receipt) => {
        console.log('Tron Transaction Receipt:', receipt);
      }).catch(console.error);

Receive Transactions via Webhook

To set up a webhook server for receiving transaction notifications in real-time:

  • Ethereum, BSC, Polygon, or Tron:
    • Start a webhook server by specifying a port and a callback function to handle the data:

      # Start a webhook server for Ethereum
      nc3Ethereum.startWebhookServer(3000, (data) => {
        console.log('Received Ethereum Transaction Data:', data);
      });
      
      # Start a webhook server for Tron
      nc3Tron.startWebhookServer(3001, (data) => {
        console.log('Received Tron Transaction Data:', data);
      });
    • The webhook server will listen for incoming transactions on the specified port and execute the provided callback function whenever a transaction is detected.

Functions

Nadcab Labs Crypto Api exposes four public methods:

  • generateAddress(privateKey):

    • Generates a new blockchain address.
    • For Ethereum-compatible chains (Ethereum, BSC, Polygon), requires a privateKey.
    • For Tron, the privateKey is not required.
  • sendTransaction(txData):

    • Sends a transaction to the specified blockchain network.
    • Accepts txData object with fields like from, to, value, gas, and gasPrice for Ethereum-compatible chains.
    • For Tron, txData includes fields like from, to, and amount.
  • getBalance(address):

    • Retrieves the balance of a specific address.
    • Accepts the address parameter and returns the balance in the smallest unit (Wei for Ethereum, SUN for Tron).
  • startWebhookServer(port, callback):

    • Sets up a webhook server to listen for incoming transactions.
    • Accepts a port number and a callback function to handle incoming transaction data.
  • setProviderUrl(providerUrl):

    • Sets or updates the provider URL for connecting to the blockchain network.
    • Accepts a providerUrl string (e.g., Infura, Alchemy, TronGrid).
  • nc3.js Initialization:

    • Initializes the library for a specific blockchain network (Ethereum, BSC, Polygon, or Tron).
    • Requires a chain parameter (e.g., 'ethereum', 'tron') and a providerUrl.
  • getTransactionReceipt(txHash):

    • Fetches the transaction receipt for a specific transaction hash (txHash).
    • Useful for checking the status of a transaction.
  • createAccount():

    • Generates a new account with a private key and address.
    • Primarily used for generating new wallets on the supported blockchains.

    License

This package is MIT licensed. (c) Nadcab Labs 2023.

Authors