Skip to content

Instantly share code, notes, and snippets.

@kevin-smets
Last active July 26, 2019 20:27
Show Gist options
  • Save kevin-smets/75f717f22a55ac628744c830c9d6b491 to your computer and use it in GitHub Desktop.
Save kevin-smets/75f717f22a55ac628744c830c9d6b491 to your computer and use it in GitHub Desktop.
Private ÐApps - Embark + IPFS (MacOS)

Private ÐApps

With these instructions, you can test a fully local and private ÐApp. Obviously it's not distributed into the cloud here, so it's more like a .. PApp? But we do simulate the full stack locally, so you can push changes to your hearts content!

Prerequisites (software)

  • Node.js (brew install node)
  • IPFS (brew install ipfs)
  • Embark (npm i -g embark)
  • TestRPC (npm i -g ethereumjs-testrpc)
  • Python + pip (brew install python)
  • IPFS key generator (pip2 install piskg or pip install --user piskg)

Obviously, these are all global dependencies and at the time of writing all these versions played nicely together, obviously results may differ. Running these in Docker or pinning the versions might be necessary at some point.

Possible cleanup

Cleanup your existing IPFS installation if you have any:

Remove all known bootstrap nodes by running ipfs bootstrap rm --all

If you want to remove all local content from your IPFS node:

# unpin all files
ipfs pin ls --type recursive | cut -d' ' -f1 | xargs -n1 ipfs pin rm

# run the garbage collector
ipfs repo gc

Generate a swarm key

First, run ipfs init. Then run piskg > ~/.ipfs/swarm.key. If you want other IPFS nodes to connect to your private network, they will need this key.

Run IPFS locally

Then start your IPFS node with the following:

export LIBP2P_FORCE_PNET=1 && ipfs daemon

Setting LIBP2P_FORCE_PNET to 1, will force IPFS to use a private network.

You should see something like Swarm is limited to private network of peers with the swarm key pass by in the logging.

If you have not done the setup correctly (e.g. missing key), you will see the following: Error: privnet: private network was not configured but is enforced by the environment

If you removed everything, going to http://localhost:5001/webui should result in a timeout. It tries to fetch the webui from the livenet, but obviously nothing can be fetched remotely. If it loads, something went wrong and you should not publish anything to this network! This means you can access remote public nodes and anything you publish will be available everywhere.

Embark

cd
embark new private-dapp
cd private-dapp
embark simulator

Other terminal:

embark run

On the right you see your full stack:

Embark 2.6.0
EthereumJS TestRPC v1.1.3 (Ethereum)
Whisper (version 2)
IPFS 0.4.11
Webserver (http://localhost:8000)

Livereload ALL the things

Hang with me, we're almost there. Contract changes and everything are picked up and handled by Embark. Changes to the frontend of the PApp are not.

npm i -g browser-sync;
browser-sync start --files 'dist/**/*' --proxy 'localhost:8000' --no-open

You can now get started on development of your contract and access it directly in the console! Make sure you're not running MetaMask, it can conflict with the builtin web3.js of Embark easily.

Deploy you (D/P)App to your private IPFS network

Now for the real test, change something to (for example) index.html like setting a unique title and running embark upload ipfs.

You'll see two lines which start with DApp available at.

If you check the url starting with http://localhost:8080/ipfs/, this will work as it accesses your local node(s).

The one starting with http://gateway.ipfs.io/ipfs/ will not work. That is unless you did not change anything to the Dapp source code, the default embark dapp has already been uploaded by someone else and the hash obviously exists on the livenet :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment