Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

trufflesuite/preserves

Repository files navigation

This is the monorepo for the truffle preserve framework which includes:

  • @truffle/preserve which is the preserve framework
  • @truffle/preserve-fs, which represents the thing you want to preserve, files
  • @truffle/preserve-to-buckets, needed to preserve your thing to textile buckets
  • @truffle/preserve-to-filecoin, needed to preserve your thing to filecoin
  • @truffle/preserve-to-ipfs, needed to preserve your thing to IPFS

The truffle preserve command comes preconfigured with the ability to preserve files to IPFS, Filecoin or Textile Buckets.

Preserve to IPFS

To preserve your files to IPFS use the --ipfs flag.

$ truffle preserve ./path --ipfs [--environment <name>]

Configuration

By default, the connection to IPFS is done with a local node presumed to be running at http://localhost:5001. This is the default for an ipfs daemon and also for ganache filecoin. It is possible to point to a different IPFS node by configuing a different URL in a truffle-config.js environment.

module.exports = {
  /* ... rest of truffle-config */

  environments: {
    /* ... other environments */

    production: {
      ipfs: {
        address: "https://ipfs.infura.io:5001",
      },
    },
  },
};

Preserve to Filecoin

To preserve your files to Filecoin use the --filecoin flag.

$ truffle preserve ./path --filecoin [--environment <name>]

Configuration

By default, the connection to Filecoin is done with a local node presumed to be running at http://localhost:7777/rpc/v0. This is the default for a mainnet or localnet Lotus or Powergate node and also for ganache filecoin. It is possible to point to a different Filecoin node by configuing a different URL in a truffle-config.js environment. Besides the connection URL, you can also configure Filecoin storage deal options such as the duration or price.

module.exports = {
  /* ... rest of truffle-config */

  environments: {
    /* ... other environments */

    development: {
      filecoin: {
        address: "http://localhost:1234/rpc/v0",
        token: "AUTH_TOKEN",
        storageDealOptions: {
          epochPrice: "2500",
          duration: 518400, // 180 days
        },
      },
    },
  },
};

Preserve to Textile Buckets

To preserve your files to Textile Buckets use the --buckets flag.

$ truffle preserve ./path --buckets [--environment <name>]

Configuration

Textile Buckets requires some configuration in order to work with truffle preserve. To get started, you need to install Textile's hub tool, register and create authentication keys.

hub init
hub keys create
 - account
 - Require Signature Authentication (recommended): N

After generating these keys, they need to be added to an environment in your truffle-config.js file as well as the name of the bucket that you want to preserve your files to - it's possible to use an existing bucket for this, or if it doesn't exist yet it will be created in the process.

module.exports = {
  /* ... rest of truffle-config */

  environments: {
    /* ... other environments */

    development: {
      buckets: {
        key: "MY_BUCKETS_KEY",
        secret: "MY_BUCKETS_SECRET",
        bucketName: "truffle-preserve-bucket",
      },
    },
  },
};

Preserving with custom preserve recipes

While Truffle comes bundled with support for IPFS, Filecoin and Textile Buckets, additional workflows (or recipes) can be defined and used.

Plugin installation / configuration

  1. Install the plugin from NPM.
npm install --save-dev truffle-preserve-to-my-server
  1. Add a plugins section to your Truffle config.
module.exports = {
  /* ... rest of truffle-config */

  plugins: ["truffle-preserve-to-my-server"],
};
  1. Add any required configuration options to your Truffle config if it's required by the plugin. Refer to the plugin's documentation for this.

Plugin usage

After installation and configuration, the plugin's tag (e.g. --my-server) will show up in truffle help preserve and can be used with truffle preserve.

truffle preserve ./path --my-server

Creating custom preserve recipes

Refer to the following resources to get started creating your own custom recipes: