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/solana

v0.1.4

Published

solana module for d11k chain

Downloads

8

Readme

@d11k-ts/solana

Modules

  • client - Custom client for communicating with solana by using @solana/web3.js

Installation

yarn add @d11k-ts/solana

Following dependencies have to be installed into your project. These are not included in @d11k-ts/solana.

yarn add axios

Documentation : Basic usage examples

Connect wallet to new SolanaClient

  • Create new Solana client
  • Network default is Mainnet
// Imports
import {SolanaClient} from '@d11k-ts/solana'
import {Network} from "@d11k-ts/client";

//Connect wallet, get address and check balance 
const connectWallet = async () => {
  let phrase = "phrase"
  // Mainnet
  const solClient = new SolanaClient({phrase})
  // DojTestnet
  // const solClient = new SolanaClient({
  //    phrase, 
  //    network: Network.DojTestnet
  //    endpoint: 'https://sol-test.h4s.dojima.network:8899'
  // })
  let address = solClient.getAddress()
  try {
    const balance = await solClient.getBalance(address)
    console.log(`Adress: ${address} with balance ${balance}`)

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

Transfer sol using SolanaClient

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

Get transaction Data & transaction History

  • Create new SolanaClient instance
  • Call getTransactionData(hash) returns hash-details
  • Call getTransactionsHistory(address) returns list of transactions (if any)
// Retrieve transaction data for a particular hash
const transactionData = async () => {
  let hash = "insert hash"
  let Address = solClient.getAddress()
  try {
    const txData = await solClient.getTransactionData(
      hash
    )
    console.log(`Transaction data ${txData}`)
  } catch (error) {
    console.log(`Caught: ${error} `)
  }
}

// Retrieve transaction history for a particular address
const transactionHistory = async () => {
  let Address = solClient.getAddress()
  try {
    const txHistory = await solClient.getTransactionsHistory({
      address: Address
    })
    console.log(`Found ${txHistory.total.toString()}`)
    txHistory.txs.forEach(tx => console.log(tx))
  } catch (error) {
    console.log(`Caught: ${error} `)
  }
}

Get gas fee for transaction

  • Solana has fixed fee client, average, fast and fastest return the same value
const fee = async () => {
  try {
    const fees = solClient.getFees()
    console.log(`Fees Fast: ${fees.average} Fastest: ${fees.fast} Average: ${fees.slow}`)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
}

Get Solana Inbound address

  • Get Solana Inbound address from hermes chain

  • Can be used in adding liquidity pool and swapping

const inboundAddr = async () => {
  try {
    const inboundAddress = await solClient.getSolanaInboundAddress()
    console.log('Inbound Address :: ', inboundAddress)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
}

Get default liquidity pool gas fee

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

Add SOL token into liquidity pool

  • Add SOL tokens into liquidity pool
  • Get Solana Inbound address from hermes chain
const addSOLToLiquidityPool = async () => {
  let amountToTransfer = 0.001
  const inboundAddress = await solClient.getSolanaInboundAddress()
  try {
    const liquidityPoolHash = await solClient.addLiquidityPool(
      amountToTransfer,
      inboundAddress,
      dojAddress,           // optional dojima address
    )
    console.log('Liquidity pool hash : ', liquidityPoolHash)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
}

Swap SOL tokens

  • Swap SOL tokens to required token using receiver address
  • Get Solana Inbound address from hermes chain
  • Supported tokens for swapping - 'BNB', 'DOT', 'DOJ', 'ETH', 'AR'
import {SwapAssetList} from '@d11k-ts/utils'
const swapSOL = async () => {
  let amountToTransfer = 0.001
  const inboundAddress = await solClient.getSolanaInboundAddress()
  try {
    const swapHash = await solClient.swap(
      amountToTransfer,
      SwapAssetList,
      inboundAddress,
      reciepient                // Respective receiver SwapAssetList token address
    )
    console.log('Swap tx hash : ', swapHash)
  } catch (error) {
    console.log(`Caught ${error}`)
  }
}

Example Code

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