Dear community,
I am looking for simple ‘Hello world’ code example(s) that will work in a local browsers with IPFS embedded such as Brave browser or connected by an extension.
My goal is to have a local/client side running vanilla javascript HTML webpage that can store some user input such as an text field in html form as IPFS CID on the users computer IPFS node.
I already searched on Google for hours. But most ipfs-js examples are server side with node.js running. I can’t expect my site visitors running node js locally and I don’t want to run it on a server on my side.
The code I created so far:
<html>
<head>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/ipfs-http-client/dist/index.min.js"> //found this libary as needed to use the IPFS HTTP client api</script>
<script>
const ipfs = create({ host: 'localhost', port: '45005', protocol: 'http' })
// found this for connecting to the local node, but gives an Uncaught ReferenceError: create is not defined
const { cid } = ipfs.add('Hello world')
// found this to add text as an IPFS CID
console.info(cid)
// found this to get the CID hash
</script>
</body>
</html>
Also I don’t understand Brave isn’t using the default port 5001, but 45005. How should I find out different setups in my code if user ports are changing.
Thanks for helping.
Kind regards,
Jurjen