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

@d11k-ts/polkadot

v0.1.4

Published

polkadot module for d11k chain

Downloads

8

Readme

@d11k-ts/polkadot

Modules

  • client - Custom client for communicating with polkadot by using @polkadot/api

Installation

yarn add @d11k-ts/polkadot

Documentation : Basic usage examples

Connect wallet to new PolkadotClient

  • Create new Polkadot client
  • Network default is Mainnet
// Imports
import { Network } from '@d11k-ts/client'
import { PolkadotClient } from '@d11k-ts/polkadot'

//Connect wallet, get address and check balance 
const connectWallet = async () => {
  let phrase = "phrase"
  // Mainnet
  const polkaClient = new PolkadotClient({phrase})
  // DojTestnet
  // const polkaClient = new PolkadotClient({ 
  //    phrase, 
  //    network: Network.DojTestnet 
  //    provider: 'wss://dotws-test.h4s.dojima.network:9944'
  // })
  let address = polkaClient.getAddress()
  try {
      const balance = await polkaClient.getBalance(address)
      console.log(`Adress: ${address} with balance ${balance}`)

    } catch (error) {
      console.log(`Caught: ${error} `)
    }
  process.exit()
}

Transfer dot using PolkadotClient

  • Create new PolkadotClient instance
  • Build transaction
  • Returns txHash as string
const transferDot = async () => {
  // First initiate PolkadotClient
  let amountToTransfer = 0.001
  let recipient = 'insert address'
  console.log("Building transaction")
  try {
    const txid = await polkaClient.transfer({ 
      recipient,
      amount: amountToTransfer
    })
    console.log(`Transaction sent: ${txid}`)
    return txid
  } catch (error) {
    console.log(`Caught: ${error} `)
  }
  process.exit()
}

Get transaction Data & transaction History

  • No code for retrieving tx data and history in @d11k-ts/polkadot.
  • View tx details in explorer
  • Mainnet : polkadot-subscan

Get gas fee for transaction

  • Retrieve gas fee for transaction from build tx
const fee = async () => {
  let amountToTransfer = 0.001
  let recipient = 'insert address'
  try {
    const fees = polkaClient.getFees({
      recipient,
      amount: amountToTransfer
    })
    console.log(`Fees Fast: ${fees.average} Fastest: ${fees.fast} Average: ${fees.slow}`)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
  process.exit()
}

Get Polkadot Inbound address

  • Get Polkadot Inbound address from hermes chain
  • Can be used in adding liquidity pool and swapping
const inboundAddr = async () => {
  try {
    const inboundAddress = await polkaClient.getPolkadotInboundAddress()
    console.log('Inbound Address :: ', inboundAddress)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
  process.exit()
}

Get default liquidity pool gas fee

  • Get Polkadot default liquidity pool gas fee from hermes chain
const defaultLPGasFee = async () => {
  try {
    const LPDefaultGasFee = await polkaClient.getDefaultLiquidityPoolGasFee()
    console.log('Liquidity pool default gas fee :: ', LPDefaultGasFee)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
  process.exit()
}

Add DOT token into liquidity pool

  • Add DOT tokens into liquidity pool
  • Get Polkadot Inbound address from hermes chain
const addDotToLiquidityPool = async () => {
  let amountToTransfer = 0.001
  const inboundAddress = await polkaClient.getPolkadotInboundAddress()
  try {
    const liquidityPoolHash = await polkaClient.addLiquidityPool(
      amountToTransfer,
      inboundAddress,
      dojAddress,           // optional dojima address
    )
    console.log('Liquidity pool hash : ', liquidityPoolHash)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
  process.exit()
}

Swap DOT tokens

  • Swap DOT tokens to required token using receiver address
  • Get Polkadot Inbound address from hermes chain
  • Supported tokens for swapping - 'AR', 'BNB', 'DOJ', 'ETH', 'SOL'
import {SwapAssetList} from '@d11k-ts/utils'

const swapDOT = async () => {
  let amountToTransfer = 0.001
  const inboundAddress = await polkaClient.getPolkadotInboundAddress()
  try {
    const swapHash = await polkaClient.swap(
       amountToTransfer,
      SwapAssetList,
      inboundAddress,
      reciepient                // Respective receiver SwapAssetList token address
    )
    console.log('Swap tx hash : ', swapHash)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
  process.exit()
}

Example Code

For sample code check out example test case in ./examples/test.ts