Lighthouse
  • 👋Introduction
  • Quick Start
  • How To
    • 🔑Create an API Key
    • 🔼Upload Data
      • 📁File
      • 🔤Text/JSON
      • 🔀Buffer
    • 🔒Upload Encrypted Data
      • 📁File
      • 🔤Text/JSON
      • 🔐Encryption Authentication
        • 📝Method 1: Signed Message
        • ⚕️Method 2: JWT
        • 📲Method 3: Passkey
    • Encryption Features
      • 👯Share File
      • ❌Revoke Access
      • 🔑Check Access Conditions
      • 🚪Token Gating
      • Chains Supported
      • 📃Access Control Conditions
      • 🔓Decrypt File
        • 🌐Browser Decrypt File
        • 💻NodeJS Decrypt File
      • 🚪Access control with zkTLS
      • 👬Account Delegation Tutorial
    • 📂List Files
    • 💁File Info
    • 💰Get Balance
    • 🔁Retrieve File
    • 💾Check for Filecoin Deals
    • 🔄IPNS - Handle Mutable Data
    • 📦Migrate Files
    • 📌Pin CID
    • 💸Pay per use
    • Resize Image
    • 💻Use CLI Tools
  • zkTLS
  • 🤝Account Delegation
  • 💾Filecoin First
    • Usage
    • 💰Pay Per Deal
  • Tutorials
    • 💸Pay to View Application
    • Use Python SDK
    • 📝Update Content with Lighthouse IPNS
    • 📹Add Video Player in UI
    • ✅Document Verification with PoDSI
    • 🎨Minting NFTs on EVM Chains
    • 🪙Minting NFTs on Solana
    • 👩‍💻Programmable Storage with Lighthouse SDK and Filecoin
    • 🔐Secure File Sharing
    • Upload Encrypted Files
    • 📄Token Gating and Custom Contract
    • 🔑Token Gating NFTs
    • 🏖️Pushing File Metadata Onchain
    • Use Radix Wallet on Lighthouse Filesdapp
  • Concepts
    • Glossary
    • IPFS CID Transition to v1
  • Support
    • 📞Contact
Powered by GitBook
On this page
  • 1) Upload via Lighthouse Smart Contract
  • Smart Contract Interface
  • Calling SubmitRaaS Functions
  • Lighthouse Raas Specs
  • 2) Building Dapps with RaaS contracts
  • 3) Why does all this matter?

Was this helpful?

Edit on GitHub
  1. Filecoin First

RaaS (renew, repair, replication) Smart Contracts

Attaching a RaaS worker on-demand to trigger storage deals for files uploaded through the Lighthouse Smart Contract

Last updated 1 year ago

Was this helpful?

In this section B, we will discuss following:

1) Upload via Lighthouse Smart Contract

In this method, we will pass a cid to Lighthouse Smart Contract deployed on the following address

  • Mainnet:

  • Calibration Testnet:

The source code for this contract can be found

You can directly interact with these deployed verified contracts directly from filfox by clicking on contract links above.

Smart Contract Interface

Within the smart contract interface, some important features are critical to the RaaS service. These include:

#
Function Name
Purpose
Key Parameters
Outcome

1

submit

Function that submits a new deal request to the oracle and will creates a new deal. By default, there will be no renewals and replications for this deal

_cid

Event: SubmitAggregatorRequest

2

submitRaaS

Function that submits a new deal request to the oracle and will creates a new deal. Here user can define deal parameters.

_cid, _replication_target, _repair_threshold, _renew_threshold

Event:SubmitAggregatorRequestWithRaaS

3

getAllDeals

Get all deal IDs for a specified cid

_cid

Deal[]

4

getActiveDeals

return all the _cid's active dealIds. Critical for replication deals.

_cid

Deal[]

5

getExpiringDeals

return all the deals' dealIds if they are expiring within epochs. Critical for renewal and repair jobs.

_cid, epochs

Deal[]

Calling SubmitRaaS Functions

You can interact with the smart contract by submitting a CID of your choice to the submitRaaS function. This will create a new deal request that the Lighthouse RaaS Worker will pick up and initiate deals.

// contractInstance is the address of the contract you deployed or the aggregator-hosted RaaS address above.
const dealStatus = await ethers.getContractAt("DealStatus", contractInstance);
// Submit the CID of the file you want to upload to the Filecoin network in the following way.
await dealStatus.submitRaaS(ethers.utils.toUtf8Bytes(newJob.cid), 2, 4, 40);

Lighthouse Raas Specs

We have deployed universal RaaS node which can be used by anyone through smart contracts. Thus, there are few things to be kept in mind while working with our RaaS implementation:-

  • The params for renewal and repair have been decided by lighthouse universally for all the deals, thus giving different params would not modify those params. This is done to handle these jobs together easily for large number of cids.

  • The cid uploaded for raas service must be pinned to IPFS so as to be retrieved by Lighthouse Deal Engine to execute raas jobs.

  • Their is maxReplication param in LighthouseDealStatus contract which is currently set to 2 for both Calibrationnet testnet and Filecoin Mainnet. This means that you can only replicate your deal to 2 different miners using Lighthouse Raas service. This would be increased soon.

2) Building Dapps with RaaS contracts

contract SampleContract {
    ILighthouseDealStatus public dealStatus;
    // initialize with lighthouse deployed contract
    constructor(address _dealStatus) {
        dealStatus = ILighthouseDealStatus(_dealStatus);
    }

    function demoSubmitRaaS(
        bytes memory _cid,
        uint256 _replication_target,
        uint256 _repair_threshold,
        uint256 _renew_threshold
    ) public returns (uint256) {
        uint256 result = dealStatus.submitRaaS(_cid, _replication_target, _repair_threshold, _renew_threshold);
        // Handle the result with dapp logic
        return result;
    }

    function demoGetAllCIDs() public view returns (bytes[] memory) {
        bytes[] memory cids = dealStatus.getAllCids();
        // Handle the cids with dapp logic.
        return cids;
    }
}

We look forward to developers developing some cool dapps using our RaaS Contracts 🙂🤩

3) Why does all this matter?

We see a bright future in enabling programmable, immutable, decentralized data storage for developers.

Lighthouse SDK is designed to be simple and easy to use. We hope that this will enable developers to easily integrate the Filecoin network as the primary data storage layer for their applications.

More importantly, this enables developers to build novel applications. Imagine a dapp or DAO that can be built to incentivize, analyze and store upload metadata on-chain. There are a couple of examples of this:

  • Rewarding $TOKEN based on the upload of a particular file and their CID.

  • Being able to track CIDs and deal IDs onchain for verification and airdropping.

For your consideration, here's some pseudocode of how you could build a simple dapp that rewards users for uploading files to the Filecoin network:

function uploadFile(bytes32 fileCID) public {
    // Check if the file has already been uploaded
    require(!fileExists(fileCID), "File already exists");

    // Check if the user's file contains the correct data
    // The logic in verifyPoDSI() depends on your specific application
    // Check out the various possibilities here https://docs.filecoin.io/smart-contracts/developing-contracts/solidity-libraries/
    require(verifyPoDSI(fileCID), "File does not contain the correct data");

    // Save the file's CID to prevent against replay attacks
    saveFile(fileCID);

    // Reward the user for uploading the file
    // You can mint them a token or send them some $FIL 
    // Read more here: https://docs.filecoin.io/smart-contracts/developing-contracts/ethereum-libraries/#example-using-an-erc20-contract
    rewardUser(msg.sender);
}

You can remove these constraints and even configure new features in RaaS through Self Hosted Raas discussed in

You can build Dapps using Raas Contracts using our ILighthouseDealStatus provided . For reference , look at following pseudocode

Building more advanced, robust DataDAOs (check out the starter kit !)

💾
👷‍♂️
Appendix E
here
here
0xd928b92E6028463910b2005d118C2edE16C38a2a
0x4015c3E5453d38Df71539C0F7440603C69784d7a
here
Upload via Lighthouse Smart contracts
Smart Contract Interface
Calling SubmitRaaS Functions
Lighthouse Raas Specs
Building Dapps with RaaS contracts
Why does all this matter?