@polywrap/ipfs-plugin-js
TypeScript icon, indicating that this package has built-in type declarations

0.9.7 • Public • Published

@polywrap/ipfs-plugin-js

IPFS Plugin allows the Polywrap JS Client to interact with IPFS.

Usage

import { PolywrapClient } from "@polywrap/client-js";
import {
  initTestEnvironment,
  providers,
  stopTestEnvironment,
} from "@polywrap/test-env-js";
import { ipfsPlugin } from "@polywrap/ipfs-plugin-js";
import createIpfsClient from "@polywrap/ipfs-http-client-lite";

// IPFS
export async function foo({

  await initTestEnvironment();

  const ipfsPluginUri = "wrap://ens/ipfs.polywrap.eth";

  ipfs = createIpfsClient(providers.ipfs);
  const sampleFileTextContents = "Hello World!";
  const sampleFileBuffer = Buffer.from(sampleFileTextContents, "utf-8");
  let ipfsAddResult = await ipfs.add(sampleFileBuffer);

  // initialize client with the ipfs plugin
  client = new PolywrapClient({
    plugins: [
      {
        uri: ipfsPluginUri,
        plugin: ipfsPlugin({
          provider: providers.ipfs,
        }),
      },
    ],
  });

  // and query ipfs
  const response = await client.invoke<string>({
    ipfsPluginUri,
    method: "cat",
    input: {
      cid: sampleFileIpfsInfo.hash.toString(),
    },
  });

  // or instantiate the plugin
  const plugin = ipfsPlugin({
    provider: providers.ipfs,
  });

  // and query ipfs
  const response' = await plugin.cat(
    { cid: sampleFileIpfsInfo.hash.toString() },
    client
  );

  await stopTestEnvironment();
})

For more usage examples see src/__tests__.

API

Full API in src/schema.graphql

Readme

Keywords

none

Package Sidebar

Install

npm i @polywrap/ipfs-plugin-js

Weekly Downloads

1

Version

0.9.7

License

MIT

Unpacked Size

84.5 kB

Total Files

38

Last publish

Collaborators

  • polywrap-build-bot
  • dorgjelli