Tech Preview: Rust IPFS + Substrate

How to create your first IPFS-powered Substrate chain

Lukasz Jedrzejczyk
4 min readAug 6, 2020

Update:

This post is outdated and the instructions below will almost certainly work. You should now refer to The offchain::ipfs Manual:

Start with a solid base of Substrate, mix in some Rust IPFS, and bake for a few months with the support of the Web3 Foundation. The result?offchain::ipfs, which brings together the Kademlia-based distributed filesystem of IPFS, with the vast blockchain network powered by Substrate.

Perhaps best of all, the entire experience is written in Rust, top to bottom.

Background

Off-Chain Workers are a feature of Substrate that allow developers to make select I/O calls at block creation time, similar to what oracles do on other chains. While the workers exist in the WASM runtime of Substrate, they utilize a communication channel to the host machine to perform the requested tasks. This allows for things like HTTP requests, local keystore access, and more.

With offchain::ipfs, native IPFS API calls to a local, fully-fledged Rust IPFS node are possible, all via the Off-Chain Worker APIs that Substrate developers are used to.

Implemented IPFS APIs

Keep in mind: this is a preview and we are currently working on expanding this list to the full extent of functionality available in Rust IPFS. Some additional elements of the Rust-IPFS API have already been prototyped, but they still need to be aligned with the IPFS side before they can be used.

  • addrs
  • addrs_local
  • bitswap_stats
  • connect
  • disconnect
  • identity
  • peers

Example use cases

This set of functionality was chosen to enable scenarios similar to the ones provided by the substrate I’m online module/pallet. For example, they could be used to:

  • periodically verify/notify/register that an IPFS bootstrapper node (or a group thereof) is online or becomes offline
  • incentivize IPFS nodes belonging to the chain to remain online using tokens

Near-future work will enable more elaborate scenarios, including obtaining files from the IPFS network etc.

Instructions

Enough explanation! If you’re eager to try this out, here’s how:

  1. Open up https://substrate.dev/docs/en/tutorials/create-your-first-substrate-chain/.
  2. Go to SET UP YOUR COMPUTER ->. Depending on your OS, you may additionally need to install llvm, llvm-dev and libclang-dev if you run into issues later.
  3. At the Compiling Substrate section:
  • in point 1, instead use the command git clone --depth 1 https://github.com/rs-ipfs/substrate/tree/offchain_ipfs
  • in point 3, in the directory with the repository cloned in point 1, instead only make sure you are in the offchain_ipfs branch with git checkout offchain_ipfs and run cargo build --release
Yep, lots of crates.

Note: if, despite having gone through point 1, you are getting build errors including Rust WASM toolchain not installed, please install it!, try using a different version of Rust nightly, e.g. rustc 1.45.0-nightly (47c3158c3 2020-06-04).

4. Skip through BACKGROUND INFORMATION -> and go through the steps in INTERACTING WITH YOUR NODE ->.

5. In Start the Front-End section, go to the linked GitHub repository and execute steps:

  • Using The Template, with the additional step of git checkout cc36b72359ca1e335425757a35e5340c346b0186 (the revision compatible with the current version of offchain::ipfs) before yarn install
  • Usage

You may interact with the template node in any way the tutorial suggests; but now you have some extra IPFS-specific bits in at the Pallet Interactor section.

Look under the Pallets / RPC choice templateModule. Note the extra log information related to IPFS: Current IPFS peers: [<peer addresses>].

Signed extrinsics available in the showcase module:

  • addAddress: attempts to connect to an IPFS node with the given address (and maintain that connection); example IPFS bootstrapper node address: /ip4/104.131.131.82/tcp/4001
  • removeAddress: disconnects from an IPFS node if currently connected to it

Queries available in the showcase module:

  • desiredConnections: returns the list of addresses the local node should maintain a connection to

Conclusion

We believe this is a powerful combination of technology but we can’t be sure without your feedback. So please, tell us what you think by opening issues on GitHub.

Equilibrium is a venture studio focused on building core infrastructure for the distributed web.

Interested in joining us? Shoot us a message here.

--

--