TAGS

filecoin-box

CREATED

UPDATED

STARS

INSTALL

...

REPOSITORY
GitHub Download
Please wait: Fetching readme...

b'# Filecoin Box\n\n![box-artwork](https://github.com/truffle-box/filecoin-box/blob/master/box-img-sm.png?raw=true)\n\nWelcome to the Filecoin box. The goal of this box is to both get you hands-on with all the official Filecoin support available within Truffle and Ganache, and to kick-start your journey into the Filecoin ecosystem and the benefits that robust decentralized storage can bring to your DApps.\n\nThe context of the box is that of a decentralized art gallery. It comprises both [Lotus](https://docs.filecoin.io/reference/lotus-api/) and [IPFS](https://ipfs.io/) nodes (simulating the process of creating a storage deal), an Ethereum node (for the deployment of the [ERC-721](https://docs.openzeppelin.com/contracts/3.x/) based NFT contracts) and a [front-end](#gallery-ui) for viewing the gallery and the assets decentrally stored within.\n\n## Requirements\n\nThe Filecoin box has the following requirements:\n\n- [Node.js](https://nodejs.org/) 12.x or later\n- [NPM](https://docs.npmjs.com/cli/) version 5.2 or later\n- Windows, Linux or MacOS\n\n## Installation\n\n```bash\n$ truffle unbox filecoin\n$ npm install\n```\n\n## Setup\n\n### Running Filecoin Ganache\n\nOnce installed, you can run Filecoin Ganache with the following command:\n\n```bash\n$ npx ganache filecoin\n```\n\nThis creates 10 accounts, each loaded with 100 [FIL](https://docs.filecoin.io/reference/#wallets), and displays both their account addresses and associated private keys.\n\n```bash\nAvailable Accounts\n==================\n(0) t3rvcqmc5otc3sh3cngqg2ttzcu7ezpco466lbafzaoygxvnzsw7e7n2zbjwhiv5fdzhs6uxm2qckwt6lp5wga (100 FIL)\n(1) t3s3la37547tijmoeiep7ktogws3tep2eqrralh7rhi2mpe46q574gceyy467356onblzvwf7ejlelo2rdsg4q (100 FIL)\n(2) t3wk7a46e2dcqb7qxeuz2zq7wodwycdgtbgdpr37hhvelfilf5yvssg5xbsolgusqsumomtmtqhnobh4carhyq (100 FIL)\n...\n```\n\nIt also starts the Lotus and IPFS daemons running over `http` and `ws` respectively:\n\n```bash\nLotus RPC listening on 127.0.0.1:7777\nIPFS RPC listening on 127.0.0.1:5001\n```\n\n### Optionally running the Filecoin Ganache GUI\n\nAn alternative to running Filecoin Ganache via the CLI is to use Filecoin Ganche UI. As per the screenshot below, this exposes all the core Filecoin protocol elements as tabs which is particularly useful if you\'re just starting out.\n\n![filecoin-ganache-ui](https://github.com/truffle-box/filecoin-box/blob/master/screenshots/filecoin-ganache-ui.png?raw=true)\n\nFilecoin Ganche UI can be downloaded [here](https://github.com/trufflesuite/ganache/releases/tag/v2.6.0-beta.3). \n\n### Running the Filecoin Network Explorer\n\n> Note that these steps will be changing (merging branch into master / main, webpack, truffle plugin, etc).\n\n```bash\n$ git clone https://github.com/trufflesuite/filecoin-network-inspector\n$ npm install\n$ git checkout ganache-changes\n$ npm run start\n```\n\nAssuming it\'s running correctly, you can open the Filecoin Network Explorer at the following: http://localhost:3000\n\n### Running Ethereum Ganache\n\n```bash\n$ npx ganache ethereum\n```\n\n```bash\nRPC Listening on 127.0.0.1:8545\n```\n\n## Creating Storage Deals\n\nA [storage deal](https://docs.filecoin.io/store/lotus/store-data/#find-a-miner) is an agreement between a client and a storage miner to store some data in the network for a given duration. Note that while in the case of Filecoin\'s mainnet, a deal must be secured with a miner before data is stored, in Filecoin Ganache a deal is reached automatically.\n\n### Via the Filecoin Network Explorer\n\nThe 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".\n\n### Via Truffle Preserve\n\n[Truffle](https://www.trufflesuite.com/docs/truffle/overview) now has a `preserve` command which allows for the \'preservation\' of files directly from the Truffle CLI. This is currently experimental and thus on specific branch; installation details available at [here](https://www.trufflesuite.com/blog/announcing-collaboration-with-filecoin).\n\nOnce installed, you\'ll be able to preserve your assets via the following command. Note that you\'ll need to include the `environments` object in your `truffle-config.js` to point at the respective node (although these are already preconfigured in the box).\n\n```\n$ truffle preserve --environment development ./assets/ --filecoin\n```\n\nFor broader help with this command run `truffle help preserve`.\n\n### Via Curl (or equivalent)\n\nLastly, you can send the following `curl` request directly to the Lotus RPC. Note that the you\'ll need to update both the wallet address (`t3s3la3754...`) and CID (`QmZTR5bcpQ...`).\n\n```bash\ncurl -X POST \\\n -H \'Content-Type: application/json\' \\\n -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}]}\' \\\n http://localhost:7777/rpc/v0\n```\n\n## Minting an NFT\n\nIn the example below, we\'ve already created a deal for the 3 assets (metadata, thumbnail, and the original asset respectively) that comprise our NFT. These are as follows, with their corresponding CIDs.\n\n- metadata ([QmS4t7rFPxaaNriXvCmALr5GYRAtya5urrDaZgkfHutdCG](https://ipfs.io/ipfs/QmS4t7rFPxaaNriXvCmALr5GYRAtya5urrDaZgkfHutdCG))\n- thumbnail - ([QmbAAMaGWpiSgmMWYTRtGsru382j6qTVQ4FDKX2cRTRso6](https://ipfs.io/ipfs/QmbAAMaGWpiSgmMWYTRtGsru382j6qTVQ4FDKX2cRTRso6))\n- asset - ([QmUWFZQrJHfCVNHXVjjb2zeowVvH7dC6rKpbdHsTdnAgvP](https://ipfs.io/ipfs/QmUWFZQrJHfCVNHXVjjb2zeowVvH7dC6rKpbdHsTdnAgvP))\n\nAssuming the local Ethereum Ganache node is running, you\'ll be able to open a console and mint a new NFT with the following steps. As the base URL is set to that of an IPFS gateway, we\'ll just need to pass in the CID to the asset metadata.\n\n```bash\n$ truffle console\ntruffle(development)> const gallery = await MyGallery.deployed()\ntruffle(development)> gallery.mint(accounts[0], "QmS4t7rFPxaaNriXvCmALr5GYRAtya5urrDaZgkfHutdCG")\n```\n\nIn the above example the owner of the NFT is set (via `accounts[0]`) to that of the first account generated by the mnemonic. If we want to transfer it to a new owner, we\'ll be able to do so with the following.\n\n### Transferring Ownership\n\n```bash\n$ truffle console\ntruffle(development)> gallery.transferFrom(accounts[0], accounts[1], 1)\n```\n\n## Gallery UI\n\nA sample gallery interface is available [here](https://truffle-box.github.io/filecoin-box/).\n\n![sample-ui](https://github.com/truffle-box/filecoin-box/blob/master/screenshots/sample-ui.png?raw=true)\n\nYou can use the following steps to run this locally...\n\n```\n$ cd ui\n$ npm install\n$ npm run start\n```\n\n## Support\n\nSupport for this box is available via the Truffle community available [here](https://www.trufflesuite.com/community). In addition, Filecoin support is available [here](https://filecoin.io/).'