{"id":29068890,"url":"https://github.com/aspectron/kaspa-wasm","last_synced_at":"2025-06-27T11:09:34.571Z","repository":{"id":251430128,"uuid":"626774672","full_name":"aspectron/kaspa-wasm","owner":"aspectron","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-03T01:25:05.000Z","size":96,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-04T00:04:33.364Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aspectron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-12T06:17:50.000Z","updated_at":"2024-08-03T00:33:19.000Z","dependencies_parsed_at":"2024-08-03T00:04:32.774Z","dependency_job_id":"33e0076a-615e-4d2a-a123-45f7af301f0f","html_url":"https://github.com/aspectron/kaspa-wasm","commit_stats":null,"previous_names":["aspectron/kaspa-wasm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aspectron/kaspa-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspectron%2Fkaspa-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspectron%2Fkaspa-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspectron%2Fkaspa-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspectron%2Fkaspa-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aspectron","download_url":"https://codeload.github.com/aspectron/kaspa-wasm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspectron%2Fkaspa-wasm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262244912,"owners_count":23281029,"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":"2025-06-27T11:09:34.327Z","updated_at":"2025-06-27T11:09:34.557Z","avatar_url":"https://github.com/aspectron.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## WASM32 bindings for Rusty Kaspa SDK\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-kaspanet/rusty--kaspa-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026color=8da0cb\u0026logo=github\" height=\"20\"\u003e](https://github.com/kaspanet/rusty-kaspa/tree/master/wasm)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/kaspa-wasm.svg?maxAge=2592000\u0026style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"20\"\u003e](https://crates.io/crates/kaspa-wasm)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-kaspa--wasm-56c2a5?maxAge=2592000\u0026style=for-the-badge\u0026logo=docs.rs\" height=\"20\"\u003e](https://docs.rs/kaspa-wasm)\n\u003cimg alt=\"license\" src=\"https://img.shields.io/crates/l/kaspa-wasm.svg?maxAge=2592000\u0026color=6ac\u0026style=for-the-badge\u0026logoColor=fff\" height=\"20\"\u003e\n\nRusty-Kaspa WASM32 bindings offer direct integration of Rust code and Rusty-Kaspa\ncodebase within JavaScript and TypeScript environments such as Node.js and Web Browsers.\n\n## Documentation\n\n- [**integrating with Kaspa** guide](https://kaspa.aspectron.org/)\n- [**Rust** documentation](https://docs.rs/kaspa-wasm/latest/kaspa_wasm/index.html)\n- [**TypeScript** documentation](https://kaspa.aspectron.org/docs/)\n\nPlease note that while WASM directly binds JavaScript and Rust resources, their names on JavaScript side\nare different from their name in Rust as they conform to the 'camelCase' convention in JavaScript and \nto the 'snake_case' convention in Rust.\n\nThe WASM32 bindings can be used in both TypeScript and JavaScript environments, where in JavaScript\ntypes will not be constrained by TypeScript type definitions.\n\n## Interfaces\n\nThe SDK is currently separated into the following top-level categories:\n\n- **RPC API** — RPC API for the Kaspa node using WebSockets.\n- **Wallet SDK** — Bindings for primitives related to key management and transactions.\n- **Wallet API** — API for the Rusty Kaspa Wallet framework.\n\n## WASM32 SDK release packages\n\nThe SDK is built as 4 packages for Web Browsers as follows:\n- KeyGen - Key \u0026 Address Generation only\n- RPC - RPC only\n- Core - RPC + Key \u0026 Address Generation + Wallet SDK\n- Full - Full SDK + Integrated Wallet\nFor NodeJS, the SDK is built as a single package containing all features.\n\n## SDK folder structure\n\nThe following is a brief overview of the SDK folder structure (as available in the release):\n\n- `web/kaspa` - **full** Rusty Kaspa WASM32 SDK bindings for use in web browsers.\n- `web/kaspa-rpc` - only the RPC bindings for use in web browsers (reduced WASM binary size).\n- `nodejs/kaspa` - **full** Rusty Kaspa WASM32 SDK bindings for use with NodeJS.\n- `docs` - Rusty Kaspa WASM32 SDK documentation.\n- `examples` folders contain examples for NodeJS and web browsers.\n- `examples/data` - folder user by examples for configuration and wallet data storage.\n- `examples/javascript` - JavaScript examples.\n- `examples/javascript/general` - General SDK examples (keys \u0026 derivation, addresses, encryption, etc.).\n- `examples/javascript/transactions` - Creating, sending and receiving transactions.\n- `examples/javascript/wallet` - Interfacing with the Rusty Kaspa Wallet framework.\n- `examples/typescript` - TypeScript examples.\n\nIf you are using JavaScript and Visual Studio Code, it is highly recommended you replicate \nthe `jsconfig.json` configuration file as is done in the SDK examples. This file allows \nVisual Studio to provide TypeScript-like code completion, type checking and documentation.\n\nIncluded documentation in the release can be accessed by loading the `docs/kaspa/index.html` \nfile in a web browser.\n\n## Building from Source\n\nTo build the WASM32 SDK from source, you need to have the Rust environment installed. To do that,\nfollow instructions in the [Rusty Kaspa README](https://github.com/kaspanet/rusty-kaspa).\n\nOnce you have Rust installed, you can build the WASM32 SDK as follows:\n\n- `./build-release` - build the release version of the WASM32 SDK + Docs. The release version also contains `debug` builds of the libraries.\n- `./build-web` - build the web package (ES6 module)\n- `./build-node` - build the NodeJS package (CommonJS module)\n- `./build-docs` - runs `build-web` and then generates TypeDoc documentation from the resulting build.\n\nPlease note that to build from source, you need to have TypeDoc installed globally via `npm install -g typedoc` (see below).\n\n## Running Web examples\n\n**IMPORTANT:** To view web examples, you need to serve them from a local web server and\nserve them from the root of the SDK folder (`kaspa-wasm32-sdk` if using a redistributable or\n`rusty-kaspa/wasm` if building from source). This is because examples use relative paths.\nWASM32 currently can not be loaded using the `file://` protocol.\n\nYou can use any web server of your choice. If you don't have one, you can run one as follows:\n```bash\ncargo install http-server\nhttp-server\n```\nAccess the examples at  [http://localhost:7878/examples/web/index.html](http://localhost:7878/examples/web/index.html).\n(Make sure to change the port if you are using a different server. Many servers will serve on \n[http://localhost:8000/examples/web/index.html](http://localhost:8000/examples/web/index.html) by default)\n\nIf building from source, you must run `build-release` or `build-web` scripts before running the examples.\n\n## Running NodeJs examples\n\nThis applies to running examples while building the project from source as some dependencies are instantiated as a part of the build process. You just need to run `node init` to initialize a local config.\n\nNOTES:\n- `npm install` will install NodeJs types for TypeScript and W3C websocket modules\n- `npm install -g typedoc` is needed for the release build to generate documentation\n- `node init` creates a local `examples/data/config.json` that contains a private key (mnemonic) use across NodeJS examples. You can override address used in some examples by specifying the address as a command line argument.\n- Majority of examples will accept following arguments: `node \u003cscript\u003e [address] [mainnet|testnet-10|testnet-11] [--address \u003caddress\u003e] [--network \u003cmainnet|testnet-10|testnet-11\u003e] [--encoding \u003cborsh|json\u003e]`.\n\n    By default all wRPC connections use Borsh binary encoding.\n\nExample:\n```bash\ncd wasm\n./build-release\ncd examples\nnpm install\nnode init\nnode nodejs/javascript/general/rpc.js\n```\n\n## Using RPC\n\nThere are multiple ways to use RPC:\n- Control over WebSocket-framed JSON-RPC protocol (you have to manually handle serialization)\n- Use `RpcClient` class that handles the connectivity automatically and provides RPC interfaces in a form of async function calls.\n\n**NODEJS:** To use WASM RPC client in the Node.js environment, you need to introduce a W3C WebSocket object \nbefore loading the WASM32 library. The compatible WebSocket library is [WebSocket](https://www.npmjs.com/package/websocket) and is included in the `kaspa` NPM package. `kaspa` package is a wrapper around `kaspa-wasm` that imports and installs this WebSocket shim in the `globalThis` object and then re-exports `kaspa-wasm` exports.\n\n\n## Loading in a Web App\n\n```html\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003cscript type=\"module\"\u003e\n            import * as kaspa from './kaspa/kaspa-wasm.js';\n            (async () =\u003e {\n                await kaspa.default('./kaspa/kaspa-wasm_bg.wasm');\n                console.log(kaspa.version());\n                // ...\n            })();\n        \u003c/script\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Loading in a Node.js App\n\n```javascript\n//\n// W3C WebSocket module shim\n// this is provided by NPM `kaspa` module and is only needed\n// if you are building WASM libraries for NodeJS from source\n//\n// @ts-ignore\n// globalThis.WebSocket = require('websocket').w3cwebsocket;\n//\n\nlet {\n    RpcClient,\n    Encoding,\n    initConsolePanicHook\n} = require('./kaspa');\n\n// enabling console panic hooks allows WASM to print panic details to console\n// initConsolePanicHook();\n// enabling browser panic hooks will create a full-page DIV with panic details\n// this is useful for mobile devices where console is not available\n// initBrowserPanicHook();\n```\n\n```javascript\n// if port is not specified, it will use the default port for the specified network\nconst rpc = new RpcClient({\n    url: \"127.0.0.1\", \n    encoding: Encoding.Borsh, \n    network : \"testnet-10\"\n});\n\n(async () =\u003e {\n    try {\n        await rpc.connect();\n        let info = await rpc.getInfo();\n        console.log(info);\n    } finally {\n        await rpc.disconnect();\n    }\n})();\n```\n\nFor more details, please follow the [**integrating with Kaspa**](https://kaspa.aspectron.org/) guide.\n\n## Creating Documentation\n\nPlease note that to build documentation from source you need to have the Rust environment installed.\nThe build script will first build the WASM32 SDK and then generate typedoc documentation from it.\n\nYou can build documentation from source as follows:\n\n```bash\nnpm install -g typedoc\n./build-docs\n```\n\nThe resulting documentation will be located in `docs/typedoc/`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faspectron%2Fkaspa-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faspectron%2Fkaspa-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faspectron%2Fkaspa-wasm/lists"}