ipfs-shipyard / ipfs-provider

Connect to IPFS via an available provider
MIT License
33 stars 9 forks source link

ipfs-provider usage #33

Closed ThalusA closed 3 years ago

ThalusA commented 3 years ago

Hi, I don't really understand why with default configuration, the ipfs-provider doesn't work. I'm currently working on a browser-only environment without anykind of advance usage with webpack, browserify or anything.

That's how I'm getting ipfs object getter:

<script src="https://cdn.jsdelivr.net/npm/orbit-db@0.26.1/dist/orbitdb.js" integrity="sha256-hyVW35Y+JfcPUDLNCNcl8ELtT0p8XQQkk8TG0qU/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/ipfs-http-client@50.1.1/dist/index.min.js" integrity="sha256-EjtfQnFY9TWI8ZHFqKjHcqgHHnrE2uQrzQgaYgKro7I=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/ipfs-provider@2.0.1/dist/index.min.js" integrity="sha256-0gpmoxZ7DiHqTnHEQM575Y8HWk1dxrlzwRejOm6yIIw=" crossorigin="anonymous"></script>
<script src="index.js"></script>
<script>
  console.log(window)
  const ipfsGetter = window.IpfsProvider.getIpfs();
  ipfs_browser(ipfsGetter, window.OrbitDB);
</script>

And that's how I'm accessing to it (index.js):

const ipfs_browser = async (ipfsGetter, OrbitDB) => {
    const ipfs = await ipfsGetter;
    console.log(ipfs)
    console.log(OrbitDB);
}

However ipfs object getter always return undefined even if window.IpfsHttpClient exists. Could you help me with that small issue ?

ThalusA commented 3 years ago

Ok so never mind. I needed js-ipfs. So now my code is like that :

<script src="https://cdn.jsdelivr.net/npm/orbit-db@0.26.1/dist/orbitdb.js" integrity="sha256-hyVW35Y+JfcPUDLNCNcl8ELtT0p8XQQkk8TG0qU/Cxo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/ipfs@0.55.3/dist/index.min.js" integrity="sha256-kAWcJOwLFbB/Pkai8zGd97qUtYVGfOVvFCsH4+RK8YY=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/ipfs-http-client@50.1.1/dist/index.min.js" integrity="sha256-EjtfQnFY9TWI8ZHFqKjHcqgHHnrE2uQrzQgaYgKro7I=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/ipfs-provider@2.0.1/dist/index.min.js" integrity="sha256-0gpmoxZ7DiHqTnHEQM575Y8HWk1dxrlzwRejOm6yIIw=" crossorigin="anonymous"></script>
<script src="index.js"></script>
<script>
  console.log(window)
  const { getIpfs, providers } = window.IpfsProvider;
  const { httpClient, jsIpfs, windowIpfs } = providers;
  const ipfsGetter = getIpfs({
    loadHttpClientModule: () => window.IpfsHttpClient,
    loadJsIpfsModule: () => window.Ipfs,
    providers: [
      windowIpfs({ permissions: { commands: ['add', 'cat', 'id', 'version'] } }),
      httpClient(),
      jsIpfs()
    ]
  });
  ipfs_browser(ipfsGetter, window.OrbitDB);
</script>