以太坊ipfs
by Niharika Singh
由Niharika Singh
动手:Infura和以太坊上的IPFS入门 (Hands On: Get Started With Infura and the IPFS on Ethereum)
为什么选择Infura? (Why Infura?)
There are a lot of pain points being faced by blockchain which may be solved by Infura and/or the InterPlanetary File System (IPFS), to some extent. These are the main challenges:
区块链面临很多难题,Infura和/或行星际文件系统(IPFS)可以在一定程度上解决这些难题。 这些是主要挑战:
- It’s expensive to store data on the Ethereum blockchain 在以太坊区块链上存储数据非常昂贵
- It’s tough to configure an Ethereum geth client 配置以太坊geth客户端很困难
- It’s tough to scale the infrastructure 扩展基础架构非常困难
If you use Infura, access to the Ethereum network and the IPFS becomes a lot faster. It no longer takes hours to sync up the geth client which uses up a huge chunk of memory and bandwidth while the entire blockchain gets downloaded.
如果您使用Infura,则访问以太坊网络和IPFS的速度将大大提高。 同步geth客户端不再花费数小时,该客户端在下载整个区块链时会占用大量内存和带宽。
Here are some other advantages that come with using Infura:
以下是使用Infura的其他一些优点:
- Huge amounts of data can be stored on the IPFS, and just the hash of the file can be stored on Ethereum. 大量数据可以存储在IPFS上,而只是文件的哈希可以存储在以太坊上。
- Infura provides secure, reliable, scalable, and easy to use APIs to access the Ethereum network and the IPFS. Developers do not have to worry about the infrastructure of an Ethereum node or an IPFS node. That is taken care of by Infura. Infura提供安全,可靠,可扩展且易于使用的API来访问以太坊网络和IPFS。 开发人员不必担心以太坊节点或IPFS节点的基础架构。 这由Infura负责。
- Infura provides TLS enabled public endpoints. Infura提供启用TLS的公共端点。
- The code is portable on Ethereum’s interface using JSON RPC, Web3. 该代码可使用JSON RPC Web3在以太坊的界面上移植。
- Infura is practically a developer’s Swiss Army knife, and also saves the deployment team from the hell of scalability issues. Infura实际上是开发人员的瑞士军刀,也使部署团队免于遭受可扩展性问题的困扰。
- And finally, Infura is trusted: 最后,Infura值得信赖:
dApp说明 (dApp Description)
Our dApp will take a file as input from a user and upload it to the IPFS by invoking an Ethereum contract. The hash of the file will be stored on Ethereum.
我们的dApp将从用户那里获取文件作为输入,并通过调用以太坊合约将其上传到IPFS。 文件的哈希值将存储在以太坊上。
This is the process we’ll go through:
这是我们要经历的过程:
- Take file as an input 将文件作为输入
- Convert file to buffer 将文件转换为缓冲区
- Upload buffer to IPFS 将缓冲区上传到IPFS
- Store hash of file returned by IPFS 存储IPFS返回的文件的哈希
- Get user’s Metamask Ethereum address 获取用户的Metamask以太坊地址
- User confirms transaction to Ethereum via Metamask 用户通过Metamask确认与以太坊的交易
- IPFS hash is written on Ethereum IPFS哈希值写在以太坊上