πΈPay per use
β οΈCurrently Under Maintenanceβ οΈ
Lighthouse offers a pay-per-use functionality for users who prefer a flexible and consumption-based approach to uploading data to Filecoin.
In the traditional method, users could access Lighthouse's upload services by generating an API key as detailed in the Quick Start section. This key allowed users to purchase data plans, enabling them to increase their upload data capacity as needed.
With the pay-per-use functionality, users can upload data without the need for API key generation and purchasing predefined data cap plans. Instead, they have to pay based on their actual usage.
The pay-per-use model can be divided into the following steps -
Fetching Price
Making Payment
Generating Auth Token
Uploading Data
Fetch Price
To obtain the cost of uploading a file in the selected token, utilize the following function:
For instance, to get the price for uploading a 1 kb file in the native token (FIL) of filecoin network -
The returned value is in the smallest denomination of the specified token (e.g., attoFIL for native filecoin token).
Making Payment
After obtaining the upload cost, users can proceed to make the payment for file upload:
For instance, to make a payment of 1 USDC on filecoin main network using an accountβs private key for uploading a file, execute
Note: For USDC, the execution time may be longer due to the requirement of an ERC20 token approval transaction followed by a transfer transaction.
Note: For calibration net, the user can get up to 100MB of free data cap for testing out the service. Recharge beyond that won't work.
Generating Auth Token
To authenticate that the user who made the payment is only authorized to upload the file, generate a one-time auth token:
The auth token expires once used for uploading a file. It looks like this:
Upload Data
The final step involves uploading the file using the generated auth token:
Upon successful upload, the response includes essential information about the uploaded file:
The uploaded file can be accessed from the IPFS gateway:
https://gateway.lighthouse.storage/ipfs/QmXnudxxXwaBRYVzy5Q9fFtqPsCgoqxLLBY6VYFfcQXRTw
The complete code for uploading a file using Lighthouseβs pay-per-use functionality -
This comprehensive guide enables users to seamlessly navigate the Lighthouse pay-per-use model and successfully upload files to Filecoin.
Last updated