IPFS_basic_use

妖碼發表於2020-12-31

IPFS基本用法

安裝成功的前提下

  • 初始化
ipfs init
> initializing ipfs node at /Users/jbenet/.go-ipfs
> generating 2048-bit RSA keypair...done
> peer identity: Qmcpo2iLBikrdf1d6QU6vXuNb6P7hwrbNPW9kLAH8eG67z
> to get started, enter:
>
>   ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme
  • 檢視是否初始化成功
ipfs cat /ipfs/<HASH>/readme
##這裡的HASH用上面生成的雜湊值填寫,也就是執行上面的ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme
  • 看到如下內容
Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗  ███████╗
██║██╔═══╝ ██╔══╝  ╚════██║
██║██║     ██║     ███████║
╚═╝╚═╝     ╚═╝     ╚══════╝

If you see this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

 -------------------------------------------------------
| Warning:                                              |
|   This is alpha software. use at your own discretion! |
|   Much is missing or lacking polish. There are bugs.  |
|   Not yet secure. Read the security notes for more.   |
 -------------------------------------------------------

Check out some of the other files in this directory:

  ./about
  ./help
  ./quick-start     <-- usage examples
  ./readme          <-- this file
  ./security-notes
  • 節點聯機
##開啟另外一個終端,不要使用同一個,因為這個是開啟一個守護程式
ipfs daemon
> Initializing daemon...
> API server listening on /ip4/127.0.0.1/tcp/5001
> Gateway server listening on /ip4/127.0.0.1/tcp/8080
  • 檢視對等方的ipfs節點地址
##這裡在切換回開始的那個終端中使用該命令
ipfs swarm peers
> /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
> /ip4/104.236.151.122/tcp/4001/p2p/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx
> /ip4/134.121.64.93/tcp/1035/p2p/QmWHyrPWQnsz1wxHR219ooJDYTvxJPyZuDUPSDpdsAovN5
> /ip4/178.62.8.190/tcp/4002/p2p/QmdXzZ25cyzSF99csCQmmPZ1NTbWTe8qtKFaZKpZQPdTFB
  • 下載檔案
##這是官方給的一個測試的伺服器,平常的話需要知道特定的雜湊值,之後我們可以使用ls命令檢視時候存在了該圖片cat.jpg
ipfs cat /ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/cat.jpg > cat.jpg
  • 上傳檔案
ipfs add <filename>

在這裡插入圖片描述

  • 檢視檔案
##ipfs公網檢視(用上面的例子來看)
https://ipfs.io/ipfs/QmdCTEjm5u6UDN6j9R7B7dbgqb7u2ELDvXJLFSqpiEEktA

在這裡插入圖片描述

  • 網頁UI管理
 localhost:5001/webui