• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

claudiobizzotto/ethereum-ipfs: A bare-bones example on how to use IPFS and Ether ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

claudiobizzotto/ethereum-ipfs

开源软件地址:

https://github.com/claudiobizzotto/ethereum-ipfs

开源编程语言:

JavaScript 99.4%

开源软件介绍:

(not so) Simple storage

A bare-bones example on how to use IPFS and Ethereum from the same application. Check this wiki for the original, Ethereum-only idea.

Note: the term blockchain, used below, can also be read as multiple copies of a giant spreadsheet.

Description

This application deploys a contract to an Ethereum blockchain (the public Ethereum testnet or a local Ethereum testnet) and uses it to keep track of an image stored in an IPFS blockchain (the public IPFS "testnet" or a local IPFS testnet). The image itself is stored in the IPFS file system - the only data stored in the Ethereum contract is the IPFS hash that corresponds to the image. [Images are used in the examples below, but any other file types could be used as well]

Requirements

  1. An Ethereum node with one or more accounts unlocked (e.g, --unlock 0), RPC enabled (--rpc) and the proper RPC CORS set up (e.g, --rpccorsdomain = "*")
  2. An IPFS node that doesn't block API calls from external origins (more on this below)
  3. A modern web browser (preferably Opera) //! opinion detected :)

Local Ethereum node

Check out this guide if you want to run a local Ethereum node.

Local IPFS node

First, install IPFS on your machine.

I suggest you don't override the IPFS directory associated to your localhost's user (normally at ~/.ipfs), so the first thing you want to do is set up an IPFS directory specific for development. You can define one under the current project's root, after you check out this repo:

$ export IPFS_PATH=.ipfs
$ ipfs init

After that, you need to loosen your IPFS node's CORS restrictions:

$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
$ ipfs config --json Gateway.HTTPHeaders.Access-Control-Allow-Origin '["*"]'

You can now start the IPFS daemon:

$ ipfs daemon

Project structure

  • ipfs.js The IPFS interface in JavaScript (repository here). You can find the source (broweserified) code here

  • web3.min.js The Ethereum interface in JavaScript (repository here)

  • NotSoSimpleStorage.sol Ethereum contract written in Solidity

  • NotSoSimpleStorage.html The web application itself. It contains the core logic behind the interactions to IPFS and Ethereum

Usage

Open NotSoSimpleStorage.html in a text editor and replace the values under the config section according to your setup:

// Config
var ipfsHost    = 'localhost',
    ipfsAPIPort = '5001',
    ipfsWebPort = '8080',
    web3Host    = 'localhost',
    web3Port    = '8545';

Now open NotSoSimpleStorage.html from your web browser (no web server needed). You'll need a JavaScript console to use the application - most web browsers come with one installed out of the box. From there, just follow the instructions on the web page.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap