简体   繁体   中英

How to use IPFS with pure html and javascript in the browser

I'm working on a decentralized p2p chat system that runs exclusively in the browser. There literally is no server to speak of. I want to persist message history, and IPFS looks like a good way to do that. However, every tutorial and example I can find requires a node.js server, React or Angular (per this )--none of which will work with what I've built.

I have identified some public IPFS gateways that I could potentially use here . But without a server hosting the IPFS api, and no html/javascript exclusive examples, how can I build this?

One idea I was going to explore was running node with express in the browser, which I've done in the past for other projects not using IPFS. But I would like to avoid that if possible.

Is using IPFS without a server hosting the page impossible at this time? What am I missing/overlooking?

I found my own answer and was able to successfully upload and retrieve a file from IPFS using js-ipfs .

One caveat is the example code in index.html at the GitHub link is referencing a local node.js module.

Simply replace:

<script src="./node_modules/ipfs/dist/index.min.js"></script>

With:

<script src="https://cdn.jsdelivr.net/npm/ipfs/dist/index.min.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM