{"id":20392300,"url":"https://github.com/wiseplat/wsh-swarm-js","last_synced_at":"2026-07-29T18:31:34.462Z","repository":{"id":57400064,"uuid":"121398881","full_name":"WISEPLAT/wsh-swarm-js","owner":"WISEPLAT","description":null,"archived":false,"fork":false,"pushed_at":"2018-02-13T15:26:07.000Z","size":57,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-09T19:33:52.939Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WISEPLAT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-13T15:24:58.000Z","updated_at":"2018-02-13T15:25:55.000Z","dependencies_parsed_at":"2022-09-19T01:10:15.078Z","dependency_job_id":null,"html_url":"https://github.com/WISEPLAT/wsh-swarm-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WISEPLAT/wsh-swarm-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WISEPLAT%2Fwsh-swarm-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WISEPLAT%2Fwsh-swarm-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WISEPLAT%2Fwsh-swarm-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WISEPLAT%2Fwsh-swarm-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WISEPLAT","download_url":"https://codeload.github.com/WISEPLAT/wsh-swarm-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WISEPLAT%2Fwsh-swarm-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278866931,"owners_count":26059671,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-15T03:43:12.143Z","updated_at":"2025-10-08T00:05:51.862Z","avatar_url":"https://github.com/WISEPLAT.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Swarm.js\n\nThis library allows you to interact with the Swarm network from JavaScript.\n\n### Getting started\n\n1. Install\n\n    ```bash\n    npm install wsh-swarm-js\n    ```\n\n2. Import\n\n    ```javascript\n    // Loads the Swarm API pointing to the official gateway\n    const swarm = require(\"wsh-swarm-js\").at(\"http://swarm-gateways.net\");\n    ```\n\n### Examples\n\n#### Uploads\n\n- With JSON:\n\n    - Raw data:\n\n        ```javascript\n        const file = \"test file\"; // could also be an Uint8Array of binary data\n        swarm.upload(file).then(hash =\u003e {\n          console.log(\"Uploaded file. Address:\", hash);\n        })\n        ```\n\n    - Directory:\n\n        To upload a directory, just call `swarm.upload(directory)`, where directory is an object mapping paths to entries, those containing a mime-type and the data (Uint8Array or UTF-8 String).\n\n        ```javascript\n        const dir = {\n          \"/foo.txt\": {type: \"text/plain\", data: \"file 0\"},\n          \"/bar.txt\": {type: \"text/plain\", data: \"file 1\"}\n        };\n        swarm.upload(dir).then(hash =\u003e {\n          console.log(\"Uploaded directory. Address:\", hash);\n        });\n        ```\n\n- From disk:\n\n    - On Node.js:\n\n        ```javascript\n        swarm.upload({\n          path: \"/path/to/thing\",      // path to data / file / directory\n          kind: \"directory\",           // could also be \"file\" or \"data\"\n          defaultFile: \"/index.html\"}) // optional, and only for kind === \"directory\"\n          .then(console.log)\n          .catch(console.log);\n        ```\n\n    - On browsers:\n\n        ```javascript\n        // only works inside an event\n        document.onClick = function() {\n          swarm.upload({pick: \"file\"}) // could also be \"directory\" or \"data\"\n            .then(alert);\n        };\n        ```\n\n#### Downloads\n\n- With JSON:\n\n    - Raw data:\n\n        ```javascript\n        const fileHash = \"a5c10851ef054c268a2438f10a21f6efe3dc3dcdcc2ea0e6a1a7a38bf8c91e23\";\n        swarm.download(fileHash).then(array =\u003e {\n          console.log(\"Downloaded file:\", swarm.toString(array));\n        });\n        ```\n\n    - Directory:\n\n        ```javascript\n        const dirHash = \"7e980476df218c05ecfcb0a2ca73597193a34c5a9d6da84d54e295ecd8e0c641\";\n        swarm.download(dirHash).then(dir =\u003e {\n          console.log(\"Downloaded directory:\");\n          for (let path in dir) {\n            console.log(\"-\", path, \":\", dir[path].data.toString());\n          }\n        });\n        ```\n\n- To disk:\n\n    - On Node.js:\n\n        ```javascript\n        swarm.download(\"DAPP_HASH\", \"/target/dir\")\n          .then(path =\u003e console.log(`Downloaded DApp to ${path}.`))\n          .catch(console.log);\n        ```\n\n    - On browser:\n\n        (Just link the Swarm URL.)\n\n#### SwarmHash\n\n```javascript\nconsole.log(swarm.hash(\"unicode string áéíóú λ\"));\nconsole.log(swarm.hash(\"0x41414141\"));\nconsole.log(swarm.hash([65, 65, 65, 65]));\nconsole.log(swarm.hash(new Uint8Array([65, 65, 65, 65])));\n```\n\n### More\n\nFor more examples, check out [examples](/examples).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiseplat%2Fwsh-swarm-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiseplat%2Fwsh-swarm-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiseplat%2Fwsh-swarm-js/lists"}