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

v0.1.5

Published

arweave module for d11k chain

Downloads

3

Readme

@d11k-ts/arweave

Modules

  • client - Custom client for communicating with arweave by using arweave

Installation

yarn add @d11k-ts/arweave

Documentation : Basic usage examples

Connect wallet to new ArweaveClient

  • Create new Arweave client
  • Network default is Mainnet
// Imports
import { ArweaveClient } from '@d11k-ts/arweave'
import { Network } from '@d11k-ts/client'

//Connect wallet, get address and check balance 
const connectWallet = async () => {
  let phrase = "phrase"
  // Mainnet
  const arClient = new ArweaveClient({phrase})
  // DojTestnet
  // const arClient = new ArweaveClient({
  //   phrase,
  //   network: Network.DojTestnet,
  //   config:{
    //   host: "ar-test.h4s.dojima.network",
    //   protocol: "https",
    //   timeout: 100000,
    // }
  // })
  let address = arClient.getAddress()
  try {
      const balance = await arClient.getBalance(address)
      console.log(`Adress: ${address} with balance ${balance}`)

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

Mint DojTestnet 'ar' tokens using ArweaveClient

  • Create new Arweave client
  • Network is set to DojTestnet
  • By default 2 AR tokens were added to address on every call
  • Note: DojTestnet tokens are not useful in Mainnet
//Connect wallet, get address, mint tokens and check balance 
const mintTokensToWallet = async () => {
  let phrase = "phrase"
  // DojTestnet
  const arClient = new ArweaveClient({
    phrase,
    network: Network.DojTestnet,
    config:{
      host: "ar-test.h4s.dojima.network",
      protocol: "https",
      timeout: 100000,
    }
  })
  let address = arClient.getAddress()
  try {
      await arClient.mintArTokens(address)
        const balance = await arClient.getBalance(address)
      console.log(`Address: ${address} with balance ${balance}`)

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

Transfer ar using ArweaveClient

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

Get transaction Data & transaction History

  • Create new ArweaveClient 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 = arClient.getAddress()
  try {
    const txData = await arClient.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 = arClient.getAddress()
  try {
    const txHistory = await arClient.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

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

Get Arweave Inbound address

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

Get default liquidity pool gas fee

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

Add AR token into liquidity pool

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

Swap AR tokens

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

const swapAR = async () => {
  let amountToTransfer = 0.001
  const inboundAddress = await arClient.getArweaveInboundAddress()
  try {
    const swapHash = await arClient.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