Filecoin Lotus Lite Node
30 January, 2023 - 7 min
I've recently embarked on a journey into the exciting world of web3. Alongside some friends, I've started working on a side project built on Filecoin. If you are not familiar with Filecoin, I believe it can be described as a decentralized storage network built using blockchain protocols.
In this article I'm going to walk through the setup of a Lotus lite node, which allows us to interact with the Filecoin network. We'll be able to create contracts (upload file), check their state/status and download files.
1. Install Macos Dependencies
First things first, we need to install the necessary dependencies for the Lotus lite node.
https://lotus.filecoin.io/lotus/install/macos/
$ brew install go bzr jq pkg-config hwloc coreutils
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2. Clone repo
After we have the dependencies we can download the hyperspace tag from the lotus repo.
git clone https://github.com/filecoin-project/lotus.git
git fetch origin
git checkout v1.20.0-hyperpsace-0119
git submodule update --recursive
3. Build lotus for Hyperspace
Once we get the repo we can now build the hyperspace version of the lotus lite node.
3.1. Additional environment vars for M1
export LIBRARY_PATH=/opt/homebrew/lib
export FFI_BUILD_FROM_SOURCE=1
export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH"
3.2. Remove existing mainnet files
rm -rf ~/.lotus/datastore //remove your lotus chain datastore
rm -rf ~/.lotus/sqlite //remove your eth tx hash map or event database if exists
3.2. Build Lotus image
make clean && make hyperspacenet
sudo make install
4. Start Lotus lite node
Now we can finally start our lite node! Leave it running in a separate terminal while you interact with it.
$ FULLNODE_API_INFO=wss://wss.hyperspace.node.glif.io/apigw/lotus lotus daemon --lite
2023-01-23T12:23:08.850Z INFO main lotus/daemon.go:219 lotus repo: /Users/vicente/.lotus
2023-01-23T12:23:08.868Z WARN cliutil util/apiinfo.go:94 API Token not set and requested, capabilities might be limited.
2023-01-23T12:23:09.773Z INFO modules modules/core.go:64 memory limits initialized {"max_mem_heap": 0, "total_system_mem": 17179869184, "effective_mem_limit": 17179869184}
2023-01-23T12:23:09.773Z WARN modules modules/core.go:124 failed to initialize cgroup-driven watchdog; err: cgroups-driven watchdog: watchdog run mode not supported
2023-01-23T12:23:09.773Z WARN modules modules/core.go:125 trying a system-driven watchdog
2023-01-23T12:23:09.773Z INFO watchdog go-watchdog@v1.3.0/watermarks.go:16 initialized watermark watchdog policy; watermarks: []; thresholds: [8589934592 10307921510 12025908428 14602888806 15461882265 15891378995 16320875724]
2023-01-23T12:23:09.773Z INFO watchdog go-watchdog@v1.3.0/watchdog.go:472 initialized heap profile capture; threshold: 0.900000; max captures: 10; dir: /Users/vicente/.lotus/heapprof
2023-01-23T12:23:09.773Z INFO modules modules/core.go:130 initialized system-driven watchdog
5. Upload a file
Before we can actually upload a file we have to create a wallet and fund it! We can use their faucet to add 5FIL to our wallet.
lotus wallet new
f1b...2erzb66q
5.1 Create sample file
For hyperspace we can use some sample image since deals are not as strict.
dd if=/dev/urandom of=5mb-filecoin-payload.bin bs=1M count=5
5.2 Generate the CAR file
$ lotus client import 5mb-filecoin-payload.bin
Import ..., Root bafykbzacebj47nl7u37knizcpzr6cgawifnvv3xb4ezlxiruqvz7skjhxzvw6
6.3 Create deal
We can now create a storage deal.
$ lotus client deal
Data CID (from lotus client import): bafykbzacebj47nl7u37knizcpzr6cgawifnvv3xb4ezlxiruqvz7skjhxzvw6
.. calculating data size
Deal duration (days): 180
Miner Addresses (f0.. f0..), none to find: t01130
.. querying miner asks
-----
Proposing from t14tg3p2tjxr6wzu6f4p7xzrndk23wdkygfcnnepi
Balance: 5 FIL
Piece size: 4MiB (Payload size: 3.565MiB)
Duration: 4320h0m0s
Total price: ~0 FIL (0 FIL per epoch)
Verified: false
Accept (yes/no): yes
.. executing
Deal (t01130) CID: bafyreihoslfpcgk6moeugyx5uuexwfg6oionbquc4fqeu4uphymuyanimu
7. Downloading our file
Once the storage deal goes through (check the states here) we can then download the file. You can check the deal id using the following command
$ lotus client list-deals
DealCid DealId Provider State On Chain? Slashed? PieceCID Size Price Duration Verified
...3hzpxipu 827 t01130 StorageDealAwaitingPreCommit N N ...bfd7h4da 1016 MiB 0 FIL 521750 false
...muyanimu 0 t01130 StorageDealCheckForAcceptance N N ...5ffijqiy 3.969 MiB 0 FIL 521709 false
Message: Provider state: StorageDealPublishing
Using it you can go to the filecoin.tools for example and find the MinerID and the PayloadCID to use on the retrieve command.
$ lotus client retrieve --provider t01130 mAXCg5AIgU8+1f6b+pqMifmPhGBZBW1ru4eEyu6I0hXP5KSe+a28 5mb-filecoin-payload.bin
Recv 0 B, Paid 0 FIL, Open (New), 0s [1674909107209474001|0]
Recv 0 B, Paid 0 FIL, DealProposed (WaitForAcceptance), 17ms [1674909107209474001|0]
Recv 0 B, Paid 0 FIL, DealAccepted (Accepted), 103ms [1674909107209474001|0]
Recv 0 B, Paid 0 FIL, PaymentChannelSkip (Ongoing), 103ms [1674909107209474001|0]
Recv 217 B, Paid 0 FIL, BlocksReceived (Ongoing), 151ms [1674909107209474001|217]
Recv 1 MiB, Paid 0 FIL, BlocksReceived (Ongoing), 728ms [1674909107209474001|1048793]
Recv 2 MiB, Paid 0 FIL, BlocksReceived (Ongoing), 858ms [1674909107209474001|2097369]
Recv 3 MiB, Paid 0 FIL, BlocksReceived (Ongoing), 957ms [1674909107209474001|3145945]
Recv 3 MiB, Paid 0 FIL, Complete (CheckComplete), 989ms [1674909107209474001|3145945]
Recv 3.565 MiB, Paid 0 FIL, BlocksReceived (CheckComplete), 994ms [1674909107209474001|3737905]
Recv 3.565 MiB, Paid 0 FIL, WaitForLastBlocks (WaitingForLastBlocks), 1.003s [1674909107209474001|3737905]
Recv 3.565 MiB, Paid 0 FIL, AllBlocksReceived (FinalizingBlockstore), 1.003s [1674909107209474001|3737905]
Recv 3.565 MiB, Paid 0 FIL, BlockstoreFinalized (Completed), 1.003s [1674909107209474001|3737905]
Success
8. Upload from IPFS
Alternatively we can upload a file directly from IPFS to the Filecoin network.
8.1 Install IPFS node
$ brew install ipfs # or alternative to your OS
8.2 Configure IPFS node
$ ipfs init
$ ipfs daemon
# stop lotus lite node
8.2 Configure Lotus lite node to use IPFS
Restart the node after editing the config. Make sure the IPFS node is running.
# edit config file (maybe ~/.lotus/config.toml)
[Client]
UseIpfs = true
8.3 Upload file to IPFS
$ ipfs add -r testfile.jpeg
added QmfDJ2aYoKEP4cTNMoyXxNbdRbBRC49pxvSbqzUJBT73VU C6675BE8-76DB-4821-A820-8E44FE642F37_1_105_c.jpeg
219.95 KiB / 219.95 KiB [====================================================================] 100.00%
8.4 Create deal
$ lotus client deal
Data CID (from lotus client import): QmfDJ2aYoKEP4cTNMoyXxNbdRbBRC49pxvSbqzUJBT73VU
.. calculating data size
Deal duration (days): 180
Miner Addresses (f0.. f0..), none to find: t01129
.. querying miner asks
-----
Proposing from t14tg3p2tjxr6wzu6f4p7xzrndk23wdkygfcnnepi
Balance: 7 FIL
Piece size: 256KiB (Payload size: 220.1KiB)
Duration: 4320h0m0s
Total price: ~0 FIL (0 FIL per epoch)
Verified: false
Accept (yes/no): yes
.. executing
Deal (t01129) CID: bafyreidviebrk3d65rey6hg5nr3mvhqotvgrias5nsqpcfbicch4622u5q
Hope this gives you an idea on how to get started with Filecoin using a Lotus Lite node.
Hope you enjoyed! Vicente
Articles in this web3 series
- Blockchain - What is a Blockchain?
- Ethereum Tokens - What are Ethereum Tokens?
- Filecoin Lite Node - How to setup a Filecoin Lite Node locally
- Lighthouse - A perpectual storage solution using IPFS and Filecoin
- Boost - Filecoin deal management tool for Storage Providers