Irys-xyz / arweave-js-sdk

JS SDK for Irys on Arweave
110 stars 95 forks source link

Funding mismatch #14

Closed lwus closed 2 years ago

lwus commented 2 years ago

Is there any guidance on how much buffer we should allow when applying funding before sending transactions? In particular, the following does not seem sufficient:

const bytes = bundlrTransactions.reduce((c, d) => c + d.data.length, 0);
const cost = await bundlr.utils.getPrice('solana', bytes);
await bundlr.fund(cost.toNumber());
for (const tx of bundlrTransactions) {
  await tx.upload();
}

The upload will fail with Not enough funds to send data in @bundlr-network/client/build/src/upload.js:221:23 and no other diagnostics

In my particular test, the number of bytes was small (<50kb) and multiplying the cost (<1e-5 SOL) by 2 was sufficient but it would be great to have specifics. Thanks!

JesseTheRobot commented 2 years ago

Bundlr nodes update their price information multiple times a minute, so applying an extra ~20% of the value (for smaller amounts) to account for value volatility should be sufficient in most cases