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

arweave-fees.js

v0.0.3

Published

Arweave gas (winston) utils repo

Downloads

14

Readme

Synopsis

This library is for developers building on Arweave network, it's a package of helper functions that makes the developers' work easier and save their time.

Install

npm install -g arweave-fees.js

Examples

1- The Arweave Equivalent Of ethgasstation.io

1.1 usage example

import { getStorageTable } from "arweave-fees.js";

const archivingCost = await getStorageTable(); 

1.2 response example

const response = {
  KB: { winston: 71327155, ar: 0.000071327155, usd: 0.0010840216822326238 },
  MB: { winston: 285308620, ar: 0.00028530862, usd: 0.004336086728930495 },
  GB: { winston: 292156026880, ar: 0.29215602688, usd: 4.440152810424827 },
  TB: {
    winston: 299167771525120,
    ar: 299.16777152512,
    usd: 4546.716477875023,
  },
  PT: {
    winston: 306347798041722900,
    ar: 306347.79804172285,
    usd: 4655837.6733440235,
  },
};

2- Check The Fee Multiplier Of A Given Transaction

Developers using Arweave L1 for broadcasting transactions usually hardcode or overwrite a fee multiplier (tx.reward) to ensure that the user of their apps will not get dropped/failed transactions.

This hotfix is an issue when the user has already defined on his end a Fee Multiplier in the Arconnect settings, and in the same time the developer's codes have hardcoded/overwritten fee multiplier. User's and developer's fee multiplier will be multiplied leading to an additional unknown AR burning for the user.

2.1 usage example

import { checkTxAgainstGasFees } from "arweave-fees.js";

// Arconnect side: fee_multiplier = 3
async function testTransaction() {
  const tx = await arweave.createTransaction(
    {
      data: "hello world!",
    },
    pk
  );

  // overwritten fee multiplier by the dev
  tx.reward = (+tx.reward * 5).toString();

  tx.addTag("Content-Type", "text/plain");

  const response = await checkTxAgainstGasFees({ txObj: tx, feeMultiplier: 5 });
  console.log(response);

  if (!response.isEqual) {
    // adjusting the tx.reward
  }

  // ...
}

2.2 response example

const response = {
  txByteSize: 12,
  theoreticalWinstonReward: 71327155,
  actualWinstonReward: 356635775,
  actualFeeMultiplier: 15, // Arconnect_multiplier * Dev_multiplier
  testedAgainstMultiplier: 5,
  isEqual: false,
};

3- Checking The Ability To Post A Transaction

Check if the user can broadcast a newly created transaction by just passing the transaction object.

3.1 usage example

import { canUpload } from "arweave-fees.js";

async function testUpload() {
  const tx = await arweave.createTransaction(
    {
      data: "hello world!",
    },
    pk
  );

  tx.reward = (+tx.reward * 5).toString();

  tx.addTag("Content-Type", "text/plain");

  const response = await canUpload({ txObj: tx });
  console.log(response);

  if (!response.canUpload) {
    throw new Error(`insufficient balance`);
  }

  await arweave.transactions.sign(tx, pk);
  await arweave.transactions.post(tx);
}

3.2 response example

const response = {
  canUpload: true,
  balanceWinstonBefore: 8829045944941,
  balanceWinstonAfter: 8828689309166,
  costInWinston: 356635775,
  costInAr: 0.000356635775,
  costInUsd: 0.0053044370497761706,
};

License

This library is licensed under the MIT license.