{"id":22165642,"url":"https://github.com/textileio/js-powergate-client","last_synced_at":"2025-07-26T11:32:19.123Z","repository":{"id":37095670,"uuid":"265867968","full_name":"textileio/js-powergate-client","owner":"textileio","description":"Typescript/Javascript client for Textile's Powergate","archived":false,"fork":false,"pushed_at":"2023-01-16T11:03:19.000Z","size":4494,"stargazers_count":46,"open_issues_count":69,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-03-02T13:32:48.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.textile.io/powergate","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/textileio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-21T14:20:57.000Z","updated_at":"2022-11-11T14:17:17.000Z","dependencies_parsed_at":"2023-02-10T02:46:04.347Z","dependency_job_id":null,"html_url":"https://github.com/textileio/js-powergate-client","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fjs-powergate-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fjs-powergate-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fjs-powergate-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/textileio%2Fjs-powergate-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/textileio","download_url":"https://codeload.github.com/textileio/js-powergate-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227673971,"owners_count":17802303,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T05:15:51.211Z","updated_at":"2024-12-02T05:15:52.071Z","avatar_url":"https://github.com/textileio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Powergate JS Client _(@textile/powergate-client)_\n===\n\n[![GitHub license](https://img.shields.io/github/license/textileio/js-powergate-client.svg)](./LICENSE)\n[![GitHub package.json version](https://img.shields.io/github/package-json/v/textileio/js-powergate-client.svg?style=popout-square)](./package.json)\n[![npm (scoped)](https://img.shields.io/npm/v/@textile/powergate-client.svg?style=popout-square)](https://www.npmjs.com/package/@textile/powergate-client)\n[![Release](https://img.shields.io/github/release/textileio/js-powergate-client.svg)](https://github.com/textileio/js-powergate-client/releases/latest)\n[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg)](https://github.com/RichardLitt/standard-readme)\n\n![Tests](https://github.com/textileio/js-powergate-client/workflows/Test/badge.svg)\n[![Docs](https://github.com/textileio/js-powergate-client/workflows/Docs/badge.svg)](https://textileio.github.io/js-powergate-client)\n\n\u003e Typescript/Javascript client for Textile's [Powergate](https://github.com/textileio/powergate).\n\nUse Powergate's multi-tiered file storage API built on Filecoin and IPFS from javascript environments such as Node, React Native, web browsers, and more.\n\n## Table of Contents\n\n- [Powergate JS Client _(@textile/powergate-client)_](#powergate-js-client-textilepowergate-client)\n  - [Background](#background)\n  - [Install](#install)\n  - [Usage](#usage)\n  - [API](#api)\n  - [Maintainers](#maintainers)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Background\n\nThe Powergate JS Client is built on top of the [Powergate](https://github.com/textileio/powergate/) gRPC APIs and contains the logic that makes it straight-forward to build those APIs into JavaScript-based systems. Using the Powergate JS Client requires access to a running instance of the Powergate. Find details on [setting up the Powergate here](https://github.com/textileio/powergate/#installation).\n\nThe JS Client provides access to the full Powergate API and therefore, does not directly manage access-control. If you plan to use the Powergate JS Client in user-facing systems, we recommend running additional middleware.\n\n## Install\n\n```\nnpm i @textile/powergate-client\n```\n\n## Usage\n\nStart by creating an instance of the client.\n\n```typescript\nimport { createPow } from \"@textile/powergate-client\"\n\nconst host = \"http://0.0.0.0:6002\" // or whatever powergate instance you want\n\nconst pow = createPow({ host })\n```\n\nMost Powergate APIs require authorization in the form of a user auth token. Users are created using the `admin` API. Powergate's backend may be configured to secure the `admin` API with an auth token, and in that case, you'll neeed to set the admin auth token on the client as shown below.\n\n```typescript\nimport { createPow } from \"@textile/powergate-client\"\n\nconst host = \"http://0.0.0.0:6002\" // or whatever powergate instance you want\n\nconst pow = createPow({ host })\n\n// Set the admin auth token if required.\npow.setAdminToken(\"\u003can admin auth token\u003e\")\n\nasync function exampleCode () {\n  const { user } = await pow.admin.users.create() // save this token for later use!\n  return user?.token\n}\n```\n\nThe returned auth token is the only thing that gives access to the corresponding user at a later time, so be sure to save it securely.\n\nA user auth token can later be set for the Powergate client so that the client authenticates with the user associated with the auth token.\n\n```typescript\nimport { createPow } from \"@textile/powergate-client\"\n\nconst host = \"http://0.0.0.0:6002\" // or whatever powergate instance you want\n\nconst pow = createPow({ host })\n\nconst token = \"\u003cpreviously generated user auth token\u003e\"\n\npow.setToken(token)\n```\n\nNow, all authenticated APIs are available for you to use.\n\n```typescript\nimport fs from \"fs\"\nimport { createPow, powTypes } from \"@textile/powergate-client\"\n\nconst host = \"http://0.0.0.0:6002\" // or whatever powergate instance you want\n\nconst pow = createPow({ host })\n\nasync function exampleCode() {\n  // get wallet addresses associated with the user\n  const { addressesList } = await pow.wallet.addresses()\n\n  // create a new address associated with the user\n  const { address } = await pow.wallet.newAddress(\"my new address\")\n\n  // get build information about the powergate server\n  const res = await pow.buildInfo()\n\n  // cache data in IPFS in preparation to store it\n  const buffer = fs.readFileSync(`path/to/a/file`)\n  const { cid } = await pow.data.stage(buffer)\n\n  // store the data using the default storage configuration\n  const { jobId } = await pow.storageConfig.apply(cid)\n\n  // watch the job status to see the storage process progressing\n  const jobsCancel = pow.storageJobs.watch((job) =\u003e {\n    if (job.status === powTypes.JobStatus.JOB_STATUS_CANCELED) {\n      console.log(\"job canceled\")\n    } else if (job.status === powTypes.JobStatus.JOB_STATUS_FAILED) {\n      console.log(\"job failed\")\n    } else if (job.status === powTypes.JobStatus.JOB_STATUS_SUCCESS) {\n      console.log(\"job success!\")\n    }\n  }, jobId)\n\n  // watch all log events for a cid\n  const logsCancel = pow.data.watchLogs((logEvent) =\u003e {\n    console.log(`received event for cid ${logEvent.cid}`)\n  }, cid)\n\n  // get information about the latest applied storage configuration,\n  // current storage state, and all related Powegate storage jobs\n  const { cidInfo } = await pow.data.cidInfo(cid)\n\n  // retrieve data stored in the user by cid\n  const bytes = await pow.data.get(cid)\n\n  // send FIL from an address managed by the user to any other address\n  await pow.wallet.sendFil(addressesList[0].address, \"\u003csome other address\u003e\", BigInt(1000))\n}\n```\n\nSee the [Node.js example app](https://github.com/textileio/js-powergate-client/tree/master/examples/node) in this repository's `examples` directory.\n\nThere are also several useful examples included in the `*.spec.ts` files of this repo.\n\n## API\n\nYou can read the [generated API docs](https://textileio.github.io/js-powergate-client/) to see the available Powergate API.\n\n## Maintainers\n\n[Textile](https://github.com/textileio)\n\n## Contributing\n\nSee [the contributing file](CONTRIBUTING.md)!\n\nPRs accepted.\n\nSmall note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.\n\n## License\n\n[MIT](LICENSE) (c) 2020 Textile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextileio%2Fjs-powergate-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftextileio%2Fjs-powergate-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftextileio%2Fjs-powergate-client/lists"}