1 of 34

Let’s Use The Filecoin Truffle Box!

�Anthony Albertorio

Community Builder, DeFi, Instructor, ConsenSys Academy�

Tom Hay

Head of Developer Relations, ConsenSys

2 of 34

What is Truffle?

  1. Truffle is a world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM).��Get idea to DApp as easily as possible.�
  2. Part of Truffle Suite along with:��Ganache - local blockchain for testing.��Drizzle - front-end libraries for dapp front-ends easier.

3 of 34

What are Truffle Boxes?

4 of 34

Why Truffle Boxes?

  • Permissionless Extension. We don’t want to be a bottleneck in innovation.�
  • Modular using familiar NPM package manager. Similar security as the modules you use everyday.�
  • Save time! Get to your goal faster. Build upon the work of others.�
  • Avoid the headaches! It’s one less thing you have to worry about.�

5 of 34

What is libp2p, IPFS and IPFS

  • libp2p. Modular network stack. modular system of protocols, specs libraries to development p2p apps. �
  • IPFS. A scalable and distributed system peer to peer for storing and accessing files, websites, applications, and data. Builds on libp2p.�
  • Filecoin. A open-source cloud storage marketplace, protocol, and cryptocurrency. Provides a system of persistent data storage. Builds on IPFS.�

6 of 34

Why Filecoin?

  • You will not have to rely on altruism with Filecoin. With economic incentives, we can have awesome uptime and asset permanence on the web. �
  • If you can assure uptime, you can trade, swap, sell and buy.�
  • Filecoin allows for people to get into economic agreements to deal with files and data.�
  • Sounds like a good mix for Ethereum!

7 of 34

Truffle + Filecoin

  • Economic incentives lead to assets. Having assets leads to the need to create:��Contracts - economic terms�Code - UI and logic�
  • Sounds like a DApp and job for Truffle!��Save time! Get from idea to dapp as quickly!�
  • Idea: Create a DApp that uses Filecoin + Ethereum. ��Be the first one to do so and become a legend!�

8 of 34

Technical Overview: Filecoin Box

  • The Filecoin Box allows you to easily integrate Filecoin into your DApps. Decentralize your front and back end!�
  • The box includes an example decentralized art gallery! �
  • It contains:�- Lotus and IPFS Nodes: (simulates storage deal process)��- Ethereum Node: (deploying ERC-721 NFT contracts)��- A front end to view decentralized assets.�

9 of 34

First Things First - Checking Requirements

  • Set up Requirements:�- Truffle�- Node.js 12.13.0 to 14.14.0�- NPM version >=6.4.1�- Windows, Linux or MacOS�
  • Make sure you have the right OS. Sorry OpenBSD.�
  • Check Node version:�$ node -v�
  • Check NPM version:�$ npm -v�
  • Check Truffle version:�$ truffle -v�

10 of 34

Setting Up The Requirements

  • If you don’t meet the requirements, let’s get setup.�
  • Use NVM (Node version manager). This allows you to switch between versions.�$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  • Get node 14.14.0 :�$ nvm install 14.14.0
  • Re-install truffle:�$ npm install -g truffle

11 of 34

Unboxing The Filecoin Box

  • Create a new folder:�$ mkdir filecoin-box
  • Enter folder:�$ cd filecoin-box
  • Unbox filecoin:�$ truffle unbox filecoin
  • Install the dependencies:�$ npm install�
  • Install peer dependencies:�$ npm i electron-webrtc@^0.3.0 wrtc@^0.4.6 prom-client@12

12 of 34

Set up Truffle Preserve

  • Like preserving fruit, Truffle allows you to preserve your files on Filecoin or IPFS!�
  • The truffle preserve command allows you to specify the files you want to preserve on the command line, and choose between the --filecoin or --ipfs.

  • Get special version of Truffle:�$ npm install -g truffle@preserves

Note: This will override your current truffle version. But it is scoped to your current node version (14.14.0). You can change your node version using nvm if you need regular truffle for another project.

13 of 34

Changing Node Version

  • If you need regular truffle for another project, you can change your node version using nvm.�
  • First install the version of node that you want. Say you want node 12.0.0�$ nvm install 12.0.0�
  • Once installed you are automatically switched to it.

  • If you want to switch back to node version 14.14.0 do the following command: �$ nvm use 14.14.0�

14 of 34

Set up Truffle Preserve

  • To use truffle preserve specify the files you want to preserve on the command line and choose between the --filecoin or --ipfs “recipes”. �Preserve to Filecoin:�$ truffle preserve ./path/to/directory --filecoin

Preserve to IPFS:

$ truffle preserve ./path/to/directory --ipfs�

15 of 34

Under the hood

  • Note: that the filecoin or ipfs recipe uses the ipfs recipe under the hood. You can choose only the ipfs recipe if you have a different set up!�
  • By default, truffle preserve comes configured to work with the Powergate localnet. �
  • You can change the IPFS and Filecoin connection information by adding the following to your truffle-config.js file. �
  • Or add Textile Buckets.

Note: this config adds a new top-level environments object. We'll be using this new configuration object as we upgrade to Truffle version 6 in the future.

👀

16 of 34

Starting Ethereum on the Ganache Local Testnet

  • First let’s set up our Ethereum local blockchain. ��With Ganache, we can spin up a test environment before deploying to test net or production. Remember smart contracts are immutable. So testing is essential.�
  • In the same ./filecoin-box folder run:�npx ganache ethereum
  • This will spin up 10 sample accounts with 100 ETH. Sorry, its test net ETH.���

17 of 34

Starting Filecoin on the Ganache Local Testnet

  • Create a new tab in your command line interface (CLI).�
  • Make sure you are in: /filecoin-box
  • Run Ganache CLI using Filecoin:�$ npx ganache filecoin
  • You will get 100 FIL and 10 sample accounts. FIL is the native token for Filecoin.�
  • This will also start the Lotus and IPFS daemons running over http and ws (websockets) protocols.

18 of 34

Or Starting the DApp - Ganache UI

  • Or you can use the Ganache UI.
  • Go to the Ganache Repo.�Via HTTPS:�$ git clone https://github.com/trufflesuite/ganache.git�Via SSH:�$ git clone git@github.com:trufflesuite/ganache.git
  • Check out the branch:�$ git checkout feat/filecoin-files
  • Then install and run:�$ npm install�$ npm run start
  • Click Filecoin Quick Start

19 of 34

What is the Filecoin Network Inspector?

  • The Filecoin network inspector interacts with several aspects of the network that are exposed through Lotus’ JS API. It includes:�
  • Simple chain explorer: info about Filecoin blocks.�
  • Miner explorer: info about all the active miners in the local Filecoin network.�
  • Marketplace: Add your files on the connected Filecoin network.�
  • Deals page: see all your previous deals and their details.��

Note: Lotus is the Protocol Labs’ GoLang implementation of the Filecoin.�Lotus JS is written in JavaScript.

20 of 34

Setting Up and Running the Filecoin Network Inspector

  • First, open a new CLI tab.�
  • Go to the Filecoin Network Inspector repo.�
  • If you have HTTPS:�$ git clone https://github.com/trufflesuite/filecoin-network-inspector.git��If you have SSH, run:�$ git clone git@github.com:trufflesuite/filecoin-network-inspector.git����

21 of 34

Setting Up and Running the Filecoin Network Inspector

  • Change into the folder:�$ cd filecoin-network-inspector
  • Then switch branches:�$ git checkout ganache-changes�
  • And install and start:�$ npm install�$ npm run start�
  • Note that your app will run on localhost:3000

22 of 34

What are Deals? 🤝

  • A Deal: when two participants in the Filecoin network can enter into a deal where one party contracts the services of the other. �There are two types of deal�
  • Storage deals: one party agrees to store data for the other for a specified length of time�
  • Retrieval deals: one party agrees to transmit specified data to the other.�
  • Learn how they work under the hood here.

23 of 34

Creating a Storage Deal via the Filecoin Explorer UI🤝

  • Before trying to create a Storage Deal make sure that the following are running:��- Filecoin Network Inspector�- Ethereum on Ganache�- Filecoin on Ganache�
  • The simplest way to store data, open the Filecoin Network Explorer and navigate to the "Market" tab. ��From here you can select a file by clicking "Choose File" followed by "Upload to the Filecoin Network".��

Note: On Filecoin's mainnet, a deal must be secured with a miner before data is stored. ��In Filecoin Ganache a deal is reached automatically.

24 of 34

Creating a Storage Deal via Truffle Preserve 🤝

  • Or use truffle preserve to create the storage deal.��$ truffle preserve --environment development ./assets/ --filecoin
  • Note: the environments object is already preconfigured in your truffle-config.js. If you want to customize it, you will need to point to to respective node from there.�
  • Note: the same principle of automatic deployment to Filecoin Ganache applies.��

25 of 34

Creating a Storage Deal via Curl 🧠 🤝

  • Lastly you could also create a storage deal via Curl�$ curl -X POST \

-H 'Content-Type: application/json' \

-d '{"jsonrpc":"2.0","id":0,"method":"Filecoin.ClientStartDeal","params":[{"Data":{"TransferType":"graphsync","Root":{"/":"QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V"},"PieceCid":null,"PieceSize":0},"Wallet":"t3s3la37547tijmoeiep7ktogws3tep2eqrralh7rhi2mpe46q574gceyy467356onblzvwf7ejlelo2rdsg4q","Miner":"t01000","EpochPrice":"2500","MinBlocksDuration":300}]}' \

http://localhost:7777/rpc/v0

  • Note: you'll need to update both the wallet address (t3s3la3754...) and CID (QmZTR5bcpQ...).��

26 of 34

Overview: Minting the NFT in Ethereum

Thumbnail - (QmbAAMaGWpiSgmMWYTRtGsru382j6qTVQ4FDKX2cRTRso6)��Asset - (QmUWFZQrJHfCVNHXVjjb2zeowVvH7dC6rKpbdHsTdnAgvP)

27 of 34

Overview: Minting the NFT on Ethereum

  • Make sure the Ethereum Ganache and Filecoin Ganache nodes are running. Use separate tabs.�
  • Open a new tab in the command line and mint a new NFT with the following steps!�$ truffle console

�truffle(development)> const gallery = await MyGallery.deployed()��truffle(development)> gallery.mint(accounts[0], "QmS4t7rFPxaaNriXvCmALr5GYRAtya5urrDaZgkfHutdCG")�

  • The NFT owner is set to accounts[0]. This is the first account generated by the mnemonic.��

28 of 34

Overview: Transferring ownership of the NFT on Ethereum

  • If we want to transfer it to a new owner, we'll be able to do so with the following.

�$ truffle console

truffle(development)> gallery.transferFrom(accounts[0], accounts[1], 1)

  • A sample view of the filecoin-box gallery is found here.�
  • “Learning never exhausts the mind.” - Leonardo Da Vinci

29 of 34

Overview: Starting the DApp locally

  • You can use the following steps to run this locally. Enter the ./ui directory.��$ cd ui�
  • Install the dependencies for the UI.�$ npm install�
  • Start the DApp:�$ npm run start
  • Viola! We have our DApp Running!�
  • “You must always start with something. Afterward you can remove all traces of reality. ”��- Pablo Picasso

30 of 34

Test Out the Filecoin Developer Preview

  1. Want to understand what is going on?�
  2. Inspect the source code:�https://github.com/truffle-box/filecoin-box
  3. Give it a star ⭐️�
  4. Use the repo �
  5. See an issue, submit an issue or pull request�
  6. We ❤️ Devs

31 of 34

More Resources - Go Deeper! 📓

A helpful Filecoin-box README.��Learn more with Proto School��IPFS Shipyard: Cool community projects��Build a Tutorial at Proto School

IPFS Docs��Filecoin Docs��Truffle Docs

32 of 34

More Resources- Reach out to us 📣

Talk to us! �#browsers3000 channel��ConsenSys Discord�(@CryptoHamilton-Never-DMsMetaMask)��(@Tom Hay)��Filecoin Slack�(Anthony Albertorio)

33 of 34

Stay SAFE: Never share your seed phrase 📣

34 of 34

Happy Building!

👷‍♂️👷‍♀️�🏗 🛠