Using ipfs with etheruem

Panda
5 min readDec 23, 2019

--

Ipfs is a decentralized tool , it’s very suitable for ethereum.

We also use Smart Contract to store “data” in the etheruem blockchain.

Today , We use Smart Contract to store “data(ipfs hash)” , for the purpose of immutability .

IPFS

What’s IPFS ?

ipfs

IPFS introduction from wiki

The InterPlanetary File System (IPFS) is a protocol and peer-to-peer network for storing and sharing data in a distributed file system. IPFS uses content-addressing to uniquely identify each file in a global namespace connecting all computing devices.

IPFS allows users to not only receive but host content, in a similar manner to BitTorrent. As opposed to a centrally located server, IPFS is built around a decentralized system of user-operators who hold a portion of the overall data, creating a resilient system of file storage and sharing. Any user in the network can serve a file by its content address, and other peers in the network can find and request that content from any node who has it using a distributed hash table (DHT).

Why we use ipfs ?

We know we can’t upload pictures on Ethereum, because uploading pictures on Ethereum has to pay a high gas fees.

gas fees

We can upload the ipfs hash to Ethereum Blockchain .

How do we do ? Let’s go with our tutorial .

Tutorial

We will use Ipfs to upload the file and deploy the Hash (Ipfs generate) on the Ethereum blockchain .

First : Prepare List

1. Chrome 
2. Metamask
3. Remix
4. IPFS Desktop / Extension
  1. Chrome

Google Chrome is a good browser can use many extensions on it .

2. Metamask

Metamask is not only a ethereum wallet but a chrome extension .

3. Remix

Remix is a smart contract complier and we also use it to test our smart contract .

4. IPFS Desktop /Extension

mac : https://github.com/ipfs-shipyard/ipfs-desktop/releases/download/v0.10.2/ipfs-desktop-0.10.2.dmgwindows : https://github.com/ipfs-shipyard/ipfs-desktop/releases/download/v0.10.2/ipfs-desktop-setup-0.10.2.exe

Second : Write smart contract on Remix

if we install metamask on browser , and we change the network to Ropsten Testnet , and get the ether from faucet .

Faucet

You can get the ether from faucet.

Remix

  1. If you first use Remix , please click the solidity button in Eviroments.

2. Create a new file on FILE EXPLORERS and we named it “ipfs_inbox.sol” .

Code on it .

pragma solidity ^0.4.23;
contract ipfs_store {
string ipfsHash;

function sendHash(string x) public {
ipfsHash = x;
}
function getHash() public view returns (string x) {
return ipfsHash;
}
}

3. Click the icon “SOLIDITY COMPILER” , and click compile ipfs_inbox.sol .

And you can see your contract ABI and Bytecode on it .

4. Change to DEPLOY & RUN TRANSACTIONS

  • First : Switch Eviroments from Javascript VM to Injected Web3
  • Second : Click the deploy button
  • Third : If the contract success deploy , and we can see our contracts.
  • Fourth : Write your IPFS Hash down .

But we didn’t upload our file on IPFS , so we must upload the file first .

Click Add Button to upload the file on IPFS .

We can see the mining.png and it’s hash .
We can copy the hash on the Remix .

We get the hash and paste it to the remix’s contract .

QmZRDUo9vTfMpZ3SHKDrtw1vm9X3dRiNVkkiXs5uCRriep

SendHash

Paste the hash .

getHash

We can see our file on ipfs , ipfs.io/ipfs/”your hash”

https://ipfs.io/ipfs/QmZRDUo9vTfMpZ3SHKDrtw1vm9X3dRiNVkkiXs5uCRriep

And you can see my photo — miner on IPFS .

Conclusion

IPFS is a good peer-to-peer applications , but it also have a problem about Speeds and peers too less .

If we want to see the anything on IPFS , we may wait too much time searching for files.

But IPFS solves a fundamental problem on the blockchain .

Too much content and pictures should not be on the blockchain .

If you like my articles , please give me claps and likes on it.

If you want to see more chinese articles , you can see our official .

Hello , I am Panda , A blockchain Researcher . If you want to contact with me :

--

--

No responses yet