The Lighthouse project (http://lighthouse.ninja/)provides a way for Ethereum smart contracts to request Filecoin storage of CIDs in IPFS, which simplifies Filecoin storage workflows from IPFS. Using Lighthouse, Ethereum developers can request verifiable storage of data to Filecoin from Ethereum smart contracts.
The project allows Ethereum developers to easily extend their IPFS storage with cryptographically verifiable and incentivized storage on Filecoin. Lighthouse greatly reduces the friction for Ethereum developers to interact with the Filecoin storage network by allowing them to store files on Filecoin by directly interacting with a Lighthouse smart contract deployed on Ethereum. This project was originally inspired by the [Quasar](https://github.com/infinitescroll/quasar) project that had been explored for Aragon and IPFS.
How it works
1) There is a Lighthouse smart contract deployed on Ethereum that can be triggered for a transaction by passing in an existing IPFS CID and config requesting Filecoin storage. The CID represents a unique ID of the file to be stored and the config represents the configuration in accordance with which the file has to be stored.
2) When a transaction is made, the smart contract emits an event with the CID and config which is intercepted by a Vulcanize DB instance. Vulcanize DB is an open source Postgres database of the Ethereum chain based on IPLD.
3) A Lighthouse node listens to this Vulcanize instance and receives the CID and config from the Vulcanize instance. Then the Lighthouse node prepares the CID and config to be sent to a Powergate instance which has been set up to make a storage deal with the Filecoin network on behalf of users. The Lighthouse node also exposes a WebSocket which gives out the storage info of a particular CID.This WebSocket is also used to retrieve back the file stored on the Filecoin network.
4) The Lighthouse node interacts with the Powergate instance to retrieve the storage info and the file itself from the Filecoin network on request.
How can you use Lighthouse?
The Lighthouse’s smart contract is deployed on the Ethereum Rinkeby testnet currently at the following address:
0xdFEa08D7c2B43498Bfe32778334c9279956057F0
You can interact with the contract by calling the store function which accepts two parameters, CID and Config via Remix or other IDE / web3 library.
Example Inputs to try –
- CID —QmTJYDuVWNnRn6g4AjRE5adZ9GwTm7Sgu2Zj75a3xibDRJ
- Config —
{ "hot": { "enabled": true, "allowUnfreeze": true, "ipfs": { "addTimeout": 900 }, "unfreezeMaxPrice": 0}, "cold": { "enabled": true, "filecoin": { "replicationFactor": 1, "dealMinDuration": 518400, "excludedMinersList": [], "trustedMinersList": [], "countryCodesList": [], "renew": { "enabled": true, "threshold": 1 }, "address": "f3rpbm3bt4muydk3iq5ainss6phht4bjbe5dq6egrx4rwzqjgwc5eruyloozvf6qjunubo467neaqsvbzyxnna", "maxPrice": 100000000000, "fastRetrieval": true, "dealStartOffset": 8640, "verifiedDeal": true } }, "repairable": false}
The CID is a unique id of the file and the Config represents the configuration of the file to be stored on the Filecoin. The Lighthouse node uses the Textile.io’s Powergate config to store data on Filecoin which you can read more about here.
When you submit the transaction to call Lighthouse, you can receive the storage status and retrieve the stored file from the WebSocket that the Lighthouse node exposes. You can run the following example of client code to achieve this:
https://github.com/nandit123/lighthouse/blob/master/client.js
node client.js
The above client code connects to the hosted Lighthouse which exposes a websocket at 13.126.82.18:3002 which you can change to a custom/local host.
Supplying a CID in the above piece of code will return the current storage status and retrieve the file back from the Filecoin network. Retrieval may take some time depending on your file size.
How to run your own Lighthouse node?
The lighthouse node is open sourced and can be run by anyone. The project repo is here: https://github.com/nandit123/lighthouse and the Smart Contract code and artifacts are available here: https://github.com/nandit123/lighthouse-contract
To run a Lighthouse node, setup Powergate and Vulcanize are required to have the whole project working end to end:
To run a Lighthouse node,
- Clone the project repo —
git clone https://github.com/nandit123/lighthouse.git
- Install all the dependencies —
npm install
- Install pm2 globally —
npm install pm2 -g
- Now run the server via —
pm2 start src/index.js --watch
- Watch logs via —
pm2 logs
Setup Powergate
- To learn about Powergate and setup — Powergate Docs
- When you have Powergate running, take the POWERGATE_URL, POW_ID, POW_TOKEN and replace them in the environment file in the Lighthouse project repo
Setup Vulcanize
- Then listen to events from our deployed smart contract. Lighthouse node is already listening to Vulcanize via graphql subscription at https://lighthouse.vdb.to/graphiql. In case you still need to set up the vulcanize watcher on your own to listen to events from the deployed smart contract, you can follow the steps here — https://gist.github.com/nandit123/2cd44760cefb6061fb8a2a2e1894e72b
Applications
As convenient infrastructure this project can be useful for Ethereum developers to request verifiable storage of data for a file without setting up their own Filecoin node. That leads to a variety of applications:
- Storage of financial data records of defi apps on Filecoin
- Long term storage of NFTs which are mostly stored on IPFS or centralized pinning services
- Integration of Filecoin storage with your current dapp without adding a new technology into your stack
- Dapps where two or more parties transfer data to each other in exchange for Ether or other tokens on the Ethereum blockchain
Future Goals
The project is just a start to connecting Ethereum and Filecoin and there are more features lined up for the future. Some of these include publishing the Filecoin storage deal status back to the ethereum blockchain, auto-renewal of storage deals from an external smart contract or paying via an external defi smart contract that earns interest for the user.
We are open to any feedback and suggestions and feel free to also propose any future features that you would like to see!
Lighthouse.ninja
http://lighthouse.ninja/ is a dapp built using Lighthouse Smart Contract and Lighthouse node. Try it !
Author
Nandit Mehra — I have been working in the web3 space for the last two years. You can connect with me on Twitter, Website, Email
Thanks for an explanation.