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

konnadex-crypto-wallet

v0.2.2

Published

Konnadex multichain crypto wallet library that supports ETHEREUM other EVM compatible blockchains E.g. Binance Smart Chain, Polygon, Avalanche etc.

Downloads

29

Readme

Konnadex Crypto Wallet

Konnadex multichain crypto wallet library that supports ETHEREUM other EVM compatible blockchains E.g. Binance Smart Chain, Polygon, Avalanche etc.

Build Version GitHub issues GitHub stars GitHub license Total Downloads

Installation

npm install konnadex-crypto-wallet

Using yarn,

yarn add konnadex-crypto-wallet

Usage

Javascript

const konnadexWallet = require('konnadex-crypto-wallet');

TypeScript

import konnadexWallet from 'konnadex-crypto-wallet';

Methods

The following methods are available with this SDK:

Generate mnemonic

This method is used to generate mnemonic. Default number of words is 12 but you can pass a number param if you want to generate more or less.

const mnemonic = konnadexWallet.generateMnemonic();

// Note: Mnemonics with less than 12 words have low entropy and may be guessed by an attacker.

Response

net idle lava mango another capable inhale portion blossom fluid discover cruise

Create Wallet

This method creates a new wallet. The method accepts a payload object as the parameter. The parameter of this payload is:

// Creating an ETHEREUM wallet.
const wallet = konnadexWallet.createWallet({
  derivationPath: "m/44'/60'/0'/0/0", // Leave empty to use default derivation path
  network: 'ETHEREUM',
}); // NOTE - Address generated will work for EVM compatible blockchains E.g. Binance smart chain, Polygon etc

Response

{
  address: '0xfBE11AC0258cc8288cA24E818691Eb062f7042E9',
  privateKey: '0xfdf745f45d1942feea79b4c0a3fc1ca67da366899f7e6cebaa06496806ca8127',
  mnemonic: 'net idle lava mango another capable inhale portion blossom fluid discover cruise'
}

Get Balance

This gets the balance of the address passed in. The method accepts an object as the parameter. The parameters for this object depending on the kind of balance to be gotten is in the form:

Native coins

// Get the ETH balance of an address.
const data = await konnadexWallet.getTokenBalance({
  address: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
}); // NOTE - For otherEVM compatible blockchains all you have to do is change the rpcUrl.

Tokens

// Get the balance of an ERC20 token.
const data = await konnadexWallet.getTokenBalance({
  address: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
  tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
}); // NOTE - For other EVM compatible blockchains all you have to do is change the rpcUrl

Response

{
  balance: 2;
}

Generate Wallet from Mnemonic

This generates a wallet from Mnemonic phrase. The method accepts an object as the parameter. The parameters that this object takes are:

// Generate an ETHEREUM wallet from mnemonic.
const wallet = konnadexWallet.generateWalletFromMnemonic({
  mnemonic:
    'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat',
  derivationPath: "m/44'/60'/0'/0/0", // Leave empty to use default derivation path
  network: 'ETHEREUM',
}); // NOTE - Address generated will work for EVM compatible blockchains E.g. Binance smart chain, Polygon etc

Response

{
  address: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57',
  privateKey: '0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',
  mnemonic: 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'
}

This generates a wallet from Mnemonic phrase and Index. The method accepts an object as the parameter. The parameters that this object takes are:

// Generate an ETHEREUM wallet from mnemonic.
const wallet = konnadexWallet.generateWalletFromMnemonic({
  mnemonic:
    'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat',
  derivationPath: "m/44'/60'/0'/0/0", // Leave empty to use default derivation path
  network: 'ETHEREUM',
  index: 0,
}); // NOTE - Address generated will work for EVM compatible blockchains E.g. Binance smart chain, Polygon etc

Response

{
  address: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57',
  privateKey: '0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',
  mnemonic: 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat',
  path :"m/44'/60'/0'/0/0"
}

This gets the address from the private key passed in. The method accepts an object as the parameter. The parameters that this object takes are:

// Get the address from the private key on the ETHEREUM network.
const address = konnadexWallet.getAddressFromPrivateKey({
  privateKey:
    '0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
  network: 'ETHEREUM',
});

Response

{
  address: '0x1C082D1052fb44134a408651c01148aDBFcCe7Fe';
}

Get Transaction

This gets the transaction receipt of a transaction from the transaction hash. The method accepts an object as the parameter. The parameters that this object takes are:

// Get the transaction receipt on ETHEREUM network.
const receipt = await konnadexWallet.getTransaction({
  hash: '0x5a90cea37e3a5dbee6e10190ff5a3769ad27a0c6f625458682104e26e0491055',
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
}); // NOTE - For other EVM compatible blockchains all you have to do is change the rpcUrl.

Response

{
  object;
}

Transfer

This transfers the amount of tokens from the source address to the destination address It takes in an object as the parameter. It allows for the transfer of the following:

ETHEREUM Network

Allows for the transfer of ETH, and overriding of transactions.

// Transferring ETH from one address to another.
const transfer = await konnadexWallet.transfer({
  recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
  amount: 1,
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
  privateKey:
    '0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
  gasPrice: '10', // Gas price is in Gwei. Leave empty to use default gas price
  data: 'Money for transportation', // Send a message
}); // NOTE - For other EVM compatible blockchains all you have to do is change the rpcUrl.

// Transferring ERC20 tokens from one address to another.
const transfer = await konnadexWallet.transfer({
  recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
  amount: 10,
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
  privateKey:
    '0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
  gasPrice: '10', // Gas price is in Gwei. leave empty to use default gas price
  tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
}); // NOTE - For other EVM compatible blockchains all you have to do is change the rpcUrl.

The optional parameters that the object takes in are: gas price, nonce, and data.

  • The gas price is the price of gas in Gwei. The higher the gas price, the faster the transaction will be. It's best to use a higher gas price than the default.
  • The nonce is the number of transactions that have been sent from the source address and is used to ensure that the transaction is unique. The transaction is unique because the nonce is incremented each time a transaction is sent.
  • The data is a string parameter used to pass across a message through the transaction. Can only be used on transfer of ETH.
// Overriding pending ETH transaction.
const transfer = await konnadexWallet.transfer({
  recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
  amount: 0,
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
  privateKey:
    '0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
  gasPrice: '10',
  nonce: 1, // The pending transaction nonce
  data: 'Money for feeding', // Send a message
});

// Overriding ERC20 token pending transaction.
const transfer = await konnadexWallet.transfer({
  recipientAddress: '0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22',
  amount: 0,
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
  privateKey:
    '0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
  gasPrice: '10',
  tokenAddress: '0xdac17f958d2ee523a2206206994597c13d831ec7',
  nonce: 1, // The pending transaction nonce
});

Response

{
  hash: '3nGq2yczqCpm8bF2dyvdPtXpnFLJ1oGWkDfD6neLbRay8SjNqYNhWQBKE1ZFunxvFhJ47FyT6igNpYPP293jXCZk';
}

Token Info

Get ERC20 Token Info

Allows for fetching ERC20 tokens info from compatible blockchains by the token address

// getting token info.

const info = await konnadexWallet.getTokenInfo({
  address: '0xeD59FD52E192A829E653F44c7d6C812b485998F1',
  network: 'ETHEREUM',
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
}); // NOTE - For other EVM compatible blockchains all you have to do is change the rpcUrl.

Response

{
  name: 'WUSDT',
  symbol: 'Wrapped USDT',
  decimals: 18,
  address: '0xeD59FD52E192A829E653F44c7d6C812b485998F1',
  totalSupply: 5000
}

Smart Contract Call

This can be used to make custom smart contract interaction by specifying the contract ABI and function types.

ETHEREUM network

// Calling a write smart contract function.
const data = await konnadexWallet.smartContractCall({
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
  network: 'ETHEREUM',
  contractAddress: '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa',
  method: 'transfer',
  methodType: 'write',
  params: ['0x2455eC6700092991Ce0782365A89d5Cd89c8Fa22', '1000000000000000000'],
  contractAbi: [
    {
      constant: false,
      inputs: [
        { name: '_to', type: 'address' },
        { name: '_value', type: 'uint256' },
      ],
      name: 'transfer',
      outputs: [{ name: '', type: 'bool' }],
      payable: false,
      stateMutability: 'nonpayable',
      type: 'function',
    },
  ],
  privateKey:
    '0f9e5c0bee6c7d06b95204ca22dea8d7f89bb04e8527a2c59e134d185d9af8ad',
}); // NOTE - For other EVM compatible blockchains all you have to do is change the rpcUrl.

// calling a read smart contract function.
const data = await konnadexWallet.smartContractCall({
  rpcUrl: 'https://rpc.ankr.com/eth_goerli',
  network: 'ETHEREUM',
  contractAddress: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
  method: 'factory',
  methodType: 'read',
  params: [],
  contractAbi: [
    {
      inputs: [],
      name: 'factory',
      outputs: [{ internalType: 'address', name: '', type: 'address' }],
      stateMutability: 'view',
      type: 'function',
    },
  ],
}); // NOTE - For other EVM compatible blockchains all you have to do is change the rpcUrl.

Response

{
  data: object;
}

Configuration

Code quality is set up for you with prettier, husky, and lint-staged. Adjust the respective fields in package.json accordingly.

Jest

Jest tests are set up to run with npm test or yarn test.

Bundle Analysis

size-limit is set up to calculate the real cost of your library with npm run size and visualize the bundle with npm run analyze.

You can also choose to install and use invariant and warning functions.