Build
ONCHAIN STORAGE
SDK
Payment API
fund()

fund(amount, multiplier?)

Funds your account with the specified number of tokens.

Parameters

Name
Type
Description
amount
BigNumber
The amount to fund in atomic units.
multiplier
number
(optional) Fee multiplier.

Returns

Type
Description
object
A JSON object with the following values.
response = {
	id, // The transaction ID of the fund transfer
	quantity, // How much is being transferred
	reward, // The amount taken by the network as a fee
	target, // The address the funds were sent to
};

You can choose to upfront fund where you cover the cost of future uploads, or use lazy-funding where you fund per-upload.

Upfront Funding

Upfront funding reduces the number of transactions required when uploading. You fund once and then when uploading, payment is deducted directly from your account. You can also withdraw any excess balance if needed.

ℹ️

Use a token-specific version of getIrysUploader() to connect to an Irys Bundler before uploading. Choose one from here.

try {
  const irys = await getIrysUploader();
 
  const fundTx = await irys.fund(irys.utils.toAtomic(0.05));
  console.log(
    `Successfully funded ${irys.utils.fromAtomic(fundTx.quantity)} ${
      irys.token
    }`
  );
} catch (e) {
  console.log("Error funding node ", e);
}

Lazy-Funding

try {
  const irys = await getIrysUploader();
 
  const pathToFile = "./myNFT.png";
  const { size } = await fs.promises.stat(pathToFile);
  const price = await irys.getPrice(size);
  await irys.fund(price);
 
  const { id } = await irys.uploadFile(pathToFile);
  console.log(
    `${pathToFile} --> Uploaded to https://gateway.irys.xyz/${id}`
  );
} catch (e) {
  console.log("Error funding node ", e);
}
ℹ️

Lazy-funding works best when using blockchains like Ethereum and Solana where transactions are finalized quickly.

Fee Multiplier

The multiplier parameter multiplies the fees we allow the network to take, in effect prioritizing the transaction. Normally you can safely ignore this parameter, however, if you're experiencing errors when funding, you can try passing a value of 1.2 or more.

try {
  const irys = await getIrysUploader();
 
  const fundTx = await irys.fund(irys.utils.toAtomic(0.05), 1.2);
  console.log(
    `Successfully funded ${irys.utils.fromAtomic(fundTx.quantity)} ${
      irys.token
    }`
  );
} catch (e) {
  console.log("Error funding node ", e);
}

Paid RPCs

When transferring tokens we use public RPCs. Sometimes these can be slow to confirm transactions. If you're experiencing an error when funding, consider using a paid RPC.

import EthereumNodeIrys from "@irys-network/node-bundler-ethereum";
 
const getIrysUploader = async () => {
  const rpcUrl = "";
  const irysUploader = await Uploader(Ethereum).withWallet(process.env.PRIVATE_KEY).withRpc(rpcUrl);
  return irysUploader;
};