IPFS
InterPlanetary File System
A P2P distributed file system based on content addressing (CID). Core infrastructure for Web3 storage.
InterPlanetary File System
A P2P distributed file system based on content addressing (CID). Core infrastructure for Web3 storage.
IPFS (InterPlanetary File System) is a P2P distributed file system developed by Protocol Labs in 2015. While conventional HTTP finds files based on server location (Location-based), IPFS uses a Content-Addressing method that finds files by the hash value of the content (CID, Content Identifier). A file with the same content has the same CID no matter where it is stored.
IPFS has three core components. First, it splits a file into 256KB chunks with a MerkleDAG structure and links them in a hash tree. Second, it stores in a distributed manner, using a DHT (Distributed Hash Table), which nodes hold which content. Third, it uses the Bitswap protocol to find nodes that hold the needed blocks and exchange data P2P.
When a file is added to IPFS, a unique CID is generated. Example: QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco. With this CID, the same file can be retrieved from any IPFS node in the world. If the file content changes by even 1 bit, a completely different CID is generated, so data integrity is automatically guaranteed.
In the Web3 ecosystem, IPFS is used as a key component for NFT metadata, DApp frontends, and decentralized website hosting. Filecoin is an incentive layer built on top of IPFS that pays token rewards to storage providers to ensure long-term data preservation. Major Web3 services such as OpenSea, Uniswap, and Audius use IPFS.
// IPFS HTTP Client (브라우저/Node.js)
import { create } from 'ipfs-http-client';
// Infura IPFS 게이트웨이 연결
const ipfs = create({
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
headers: {
authorization: 'Basic ' + btoa(PROJECT_ID + ':' + PROJECT_SECRET)
}
});
// 파일 업로드
async function uploadFile(content) {
const { cid } = await ipfs.add(content);
console.log('CID:', cid.toString());
// CID: QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco
return cid;
}
// JSON 메타데이터 업로드 (NFT용)
async function uploadNFTMetadata(metadata) {
const json = JSON.stringify(metadata);
const { cid } = await ipfs.add(json);
return `ipfs://${cid}`; // ipfs://Qm...
}
// 파일 가져오기
async function getFile(cid) {
const chunks = [];
for await (const chunk of ipfs.cat(cid)) {
chunks.push(chunk);
}
return Buffer.concat(chunks).toString();
}
// 디렉토리 업로드
async function uploadDirectory(files) {
const result = await ipfs.addAll(files, { wrapWithDirectory: true });
for await (const file of result) {
console.log(`${file.path}: ${file.cid}`);
}
}
# IPFS 설치 (macOS)
brew install ipfs
# IPFS 노드 초기화
ipfs init
ipfs daemon # 노드 시작 (별도 터미널)
# 파일 추가 (로컬 노드에 저장)
ipfs add myfile.txt
# added QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco myfile.txt
# 디렉토리 전체 추가
ipfs add -r ./my-website/
# 마지막 출력이 루트 디렉토리 CID
# 파일 가져오기
ipfs cat QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco
ipfs get QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco -o output.txt
# 핀 고정 (가비지 컬렉션 방지)
ipfs pin add QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco
ipfs pin ls # 핀 목록 확인
# IPNS (가변 이름 시스템)
ipfs name publish QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco
# Published to k51qzi5uqu...: /ipfs/Qm...
# 공개 게이트웨이로 접근
curl https://ipfs.io/ipfs/QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco
curl https://cloudflare-ipfs.com/ipfs/Qm...
import ipfshttpclient # pip install ipfshttpclient
# 로컬 IPFS 노드 연결
client = ipfshttpclient.connect('/ip4/127.0.0.1/tcp/5001')
# 파일 추가
result = client.add('myfile.txt')
print(f"CID: {result['Hash']}")
# CID: QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco
# 바이트 데이터 추가
data = b'Hello IPFS!'
result = client.add_bytes(data)
print(f"CID: {result}")
# JSON 추가 (NFT 메타데이터)
metadata = {
"name": "My NFT",
"description": "An awesome NFT",
"image": "ipfs://QmImageCID..."
}
result = client.add_json(metadata)
print(f"Metadata CID: {result}")
# 파일 가져오기
content = client.cat(result['Hash'])
print(content.decode('utf-8'))
# 디렉토리 추가
result = client.add('my-website/', recursive=True)
for item in result:
print(f"{item['Name']}: {item['Hash']}")
# 핀 고정
client.pin.add('QmXoypizjW3WknFiJnKLwHCnL72vedxjQkDDP1mXWo6uco')
# 노드 정보 확인
info = client.id()
print(f"Peer ID: {info['ID']}")
"Let's upload the NFT metadata and images to IPFS and store them in the token URI with the ipfs:// scheme. Since a CID is a content hash, the metadata can't be tampered with once minted. If we use a pinning service such as Pinata or NFT.Storage, permanent preservation is also guaranteed."
"If we deploy the frontend to IPFS, it becomes decentralized with no single point of failure. If we set up a CI/CD pipeline with Fleek or 4EVERLAND, it deploys automatically with just a git push, and if we connect an ENS domain, it can be accessed at myapp.eth. If we use the Cloudflare IPFS gateway, loading speed also improves."
"IPFS uses content addressing, which differs from HTTP's location-based addressing. Since the same file has the same CID anywhere in the world, it can be fetched from the nearest node, which has a CDN-like effect. Combined with Filecoin, long-term storage is also guaranteed through economic incentives."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
If you only add a file to IPFS, it will be deleted by garbage collection. Be sure to use a pinning service such as Pinata, Infura, or NFT.Storage, or pin the file on your own node.
IPFS is immutable storage. Modifying a file generates a new CID. For frequently changing data, consider solutions such as IPNS or OrbitDB.
Public gateways such as ipfs.io have rate limits and availability issues. In production, run your own gateway or use paid plans such as Cloudflare IPFS or Infura.
Replicate important files across at least 2 pinning services. Use CIDv1 to ensure URL compatibility. Package large files as CAR files. Encrypt sensitive data before uploading.