A simple tutorial for starting an express server and storing data on the Filecoin Network in under 5 minutes.
- Make sure you have homebrew.
- Make sure you run
xcode-select -p
, if the command does not return a response, runxcode-select --install
- Make sure you run
brew install node
- Make sure you run
brew install go
brew install docker
.- Install Docker for Desktop if you are running MacOS.
You will need to run three simultaneous terminal windows:
In Terminal window 1:
- Clone the Lotus DevNet repository:
[email protected]:textileio/lotus-devnet.git
- Run
docker run --name texdevnet -e TEXLOTUSDEVNESPEED=1500 -p 1234:7777 textile/lotus-devnet
In Terminal window 2:
- Clone the Powergate repository:
[email protected]:textileio/powergate.git
cd powergate
- Build and install the CLI:
make build-pow
- Build the Powergate server:
make build-powd
cd docker
make devnet
In Terminal window 3:
Run these commands to start the client locally.
git clone [email protected]:filecoin-project/filecoin-client-tutorial.git
cd filecoin-client-tutorial
npm install
The main API you will interact with is the Filecoin File System (FFS).
//import express server
import express from "express";
import fs from "fs"
import { ffs, createPow } from "@textile/powergate-client"
const pow = createPow({ host:"http://0.0.0.0:6002" })
const server = express();
server.listen(8080, async () => {
//create a new FFS instance.
const { token } = await pow.ffs.create()
console.log({token});
//set the auth token that the Powergate client to use.
pow.setToken(token)
// cache data in IPFS in preparation to store it using FFS
const { cid } = await pow.ffs.addToHot(buffer)
console.log({cid});
const buffer = fs.readFileSync(`dog.jpg`)
// store the data in FFS using the default storage configuration
const { jobId } = await pow.ffs.pushConfig(cid)
console.log({jobId});
// watch the FFS job status to see the storage process progressing
const cancel = pow.ffs.watchJobs((job) => {
console.log({job})
if (job.status === ffs.JobStatus.CANCELED) {
console.log("job canceled")
} else if (job.status === ffs.JobStatus.FAILED) {
console.log("job failed")
} else if (job.status === ffs.JobStatus.SUCCESS) {
console.log("job success!")
}
}, jobId);
});
- Run
node .
Go to the Filecoin Client to see the full end to end application.