Skip to main content

Configure Filehub

This topic describes the steps to set up and manage a Filehub instance effectively. It covers how to register Filechains, toggle file storage payments on or off, and establish cross-chain asset payments. Proper setup ensures streamlined operations in file storage, payment handling, and Filechain management.

Step 1: Initialize Filehub

Start by initializing your Filehub with the required parameters. These should include the URL for the Directory Node and the specific blockchain RID for your Filehub instance.

note

Make sure to install the filehub package via npm:

npm install filehub
const filehub = new Filehub({
directoryNodeUrlPool: DIRECTORY_NODE_URL_POOL, // URL for Directory Node
blockchainRid: FILEHUB_BLOCKCHAIN_RID, // Blockchain RID for the Filehub
});

Step 2: Set up admin privileges

Use the private key of the Filehub or Filechain administrator to grant admin privileges, depending on which operations you need to perform.

note

Make sure to install the postchain-client package via npm if you haven't already:

npm install postchain-client
const admin = newSignatureProvider({ privKey: FILEHUB_ADMIN_PRIVKEY });
const filehubAdministrator = new FilehubAdministrator(filehub, admin);

Step 3: Register a Filechain

To enable a Filechain for file storage operations, register it with your Filehub. Providing an EVM address during registration assigns administrative control over the Filechain and allows for fee collection.

await filehubAdministrator.registerFilechain(
FILECHAIN_BLOCKCHAIN_RID, // Unique RID for Filechain
FILECHAIN_ADMIN_EVM_ADDRESS // Admin EVM address for the Filechain
);

Step 4: Enable/Disable a Filechain

You can disable a Filechain when its storage capacity is full or for maintenance purposes. Once disabled, the Filechain will not accept any new file storage requests. Re-enable it when it is ready to handle new file uploads.

// Disable a Filechain
await filehubAdministrator.disableFilechain(FILECHAIN_BLOCKCHAIN_RID);

// Enable a Filechain
await filehubAdministrator.enableFilechain(FILECHAIN_BLOCKCHAIN_RID);

Step 5: Configure payment systems

Configure the asset for file storage payments. Ideally, select an asset from the Economy Chain for this purpose.

await filehubAdministrator.configureCrosschainAsset(ft4Asset, issuingChain);

Step 6: Enable/Disable payments

Administrators have the ability to enable or disable payments for file storage. Disabling payments stops file uploads until you enable payments again.

// Enable payments for file storage
await filehubAdministrator.enablePayments();

// Disable payments for file storage
await filehubAdministrator.disablePayments();

After completing these steps, your Filehub will be equipped to manage file storage, handle payments, and oversee Filechain operations efficiently. For more detailed configurations and integrations, consult the Filehub API documentation.