Payment
fund(amount, multiplier?)
The fund(amount, multiplier?) function enables account funding with specified tokens.
Parameters
| Name | Type | Description |
|---|---|---|
| amount | BigNumber | The amount to fund in atomic units |
| multiplier | number | (optional) Fee multiplier |
Returns
| Type | Description |
|---|---|
| object | JSON object containing fund transfer details |
Response structure:
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
};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. Excess balances can be withdrawn using the withdrawBalance() method.
Note
Use a token-specific version of
getIrysUploader() to connect to an Irys Bundler before uploading.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
Fund per-upload based on calculated costs.
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);
}Note
Lazy-funding works best when using blockchains like Ethereum and Solana where transactions are finalized quickly.
Fee Multiplier
The multiplier parameter scales network fees to prioritize transactions. If funding errors occur, try values like 1.2 or higher.
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
Public RPC delays can cause funding issues. Consider implementing paid RPC services.
import { Uploader } from "@irys/upload";
import { Ethereum } from "@irys/upload-ethereum";
const getIrysUploader = async () => {
const rpcUrl = "";
const irysUploader = await Uploader(Ethereum)
.withWallet(process.env.PRIVATE_KEY)
.withRpc(rpcUrl);
return irysUploader;
};