We will create a simple datastore solution using IPFS and Ethereum. IPFS provides a convenient interface for distributed data storage, with a hash-based content address for reference to our file. This address will be stored in our smart contract on a private Ethereum blockchain. To retrieve the latest data, we will fetch the address from our blockchain and query IPFS for the associated file.
Windows: For Windows users, download the latest stable release, extract it, download the zip file, extract geth.exe from zip, open a command terminal and type:
Mac/Linux: For Mac and Linux users, download the prebuilt package, then untar and move the binary to your executables $PATH as follows:
tar xvfz go-ipfs.tar.gz
mv go-ipfs/ipfs /usr/local/bin/ipfs
Windows: For Windows users, download the prebuilt package, then unzip and move ipfs.exe to your %PATH%.
To test that your IPFS installation worked, in your terminal (Mac/Linux) or command prompt (Windows) window, run:
ipfs help
The help menu describing IPFS actions will be printed out.
Initialize an Ethereum node
We will start by setting up a private Ethereum blockchain on your local machine.
Setup Geth
Create a new directory for your private blockchain. In your terminal (Mac/Linux) or command prompt (Windows) window, navigate to the directory and create a new account:
geth --datadir="./" account new
Enter a password when prompted for your local Ethereum account. Geth will create a keystore directory and store the account file in the keystore.
Genesis Block
Setting up a private blockchain requires defining a genesis block, which sets the initial parameters and token distribution.
In the directory containing your account, copy/paste/save the following JSON into a file called genesisblock.json:
The --datadir flag tells geth the path for storing blockchain data. The --networkid flag gives your private blockchain a unique reference ID. The --rpc and related flags enable remote procedure call (RPC) functionality for web3. The --minerthreads flag enables the specified number of CPU threads for mining. The --mine flag indicates the mine function for processing transactions and propagating smart contracts through the network. The --nodiscover and --maxpeers flag disables peer discovery mechanisms. The --unlock 0 flag unlocks the first account in the system. The --console flag enables the REPL terminal.
As this is our first time running the --mine flag, wait for the DAG file to be generated. You will see Generating DAG: xx% for a couple minutes. This is a one-time operation.
Initialize IPFS
While we wait for the DAG to be generated, let's setup IPFS. Start by initializing IPFS and modifying CORS restrictions:
luckychain - Intel SGX and IPFS-based blockchain implementing Proof of Luck.
Ethereum
Ethereum - Ethereum is a decentralized platform that runs smart contracts: applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third party interference.
web3.js - the Ethereum compatible JavaScript API which implements the Generic JSON RPC spec.
请发表评论