Build
ONCHAIN STORAGE
SDK
API
fund()

irys.fund(amount)

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.

try {
  const irys = await getIrys();
 
  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 getIrys();
 
  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 getIrys();
 
  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.

const network = "testnet";
const providerUrl = ""; // Paid RPC URL
const token = "ethereum";
const privateKey = process.env.PRIVATE_KEY;
 
const irys = new Irys({
  network, // URL of the node you want to connect to
  token, // Currency used for payment
  key: privateKey, // ETH or SOL private key
  config: { providerUrl },
});