{"id":39525448,"url":"https://github.com/machinefi/w3bstream-wasm-assemblyscript-sdk","last_synced_at":"2026-01-18T06:23:19.110Z","repository":{"id":65663382,"uuid":"573227238","full_name":"machinefi/w3bstream-wasm-assemblyscript-sdk","owner":"machinefi","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-26T03:04:41.000Z","size":1431,"stargazers_count":1,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-01-26T06:01:51.076Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/machinefi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-12-02T01:08:40.000Z","updated_at":"2024-01-26T06:01:51.077Z","dependencies_parsed_at":null,"dependency_job_id":"cd222945-033c-44c2-a3c9-ccfbcab096cf","html_url":"https://github.com/machinefi/w3bstream-wasm-assemblyscript-sdk","commit_stats":{"total_commits":42,"total_committers":2,"mean_commits":21.0,"dds":"0.30952380952380953","last_synced_commit":"b2ccab1ae7af09757367c077280dd402d87b192f"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/machinefi/w3bstream-wasm-assemblyscript-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinefi%2Fw3bstream-wasm-assemblyscript-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinefi%2Fw3bstream-wasm-assemblyscript-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinefi%2Fw3bstream-wasm-assemblyscript-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinefi%2Fw3bstream-wasm-assemblyscript-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/machinefi","download_url":"https://codeload.github.com/machinefi/w3bstream-wasm-assemblyscript-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/machinefi%2Fw3bstream-wasm-assemblyscript-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28531995,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"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":"2026-01-18T06:23:19.047Z","updated_at":"2026-01-18T06:23:19.096Z","avatar_url":"https://github.com/machinefi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @w3bstream/wasm-sdk\n\nThis is the official assemblyscript sdk for W3bstream.\n\n## Installation\nThe package requires node.js `\u003e=16.0.0`\n\n```bash\nnpm install @w3bstream/wasm-sdk\n```\n\n\n## Useage\n\n**Your must export alloc function from @w3bstream/wasm-sdk for w3bstream vm**\n\n\n### ExecSQL \u0026 QuerySQL\n\n#### First, you need to create a project with database schema for wasm db storage\n\n[Create Database Schema](https://github.com/machinefi/w3bstream/blob/main/HOWTO.md#create-project-with-database-schema-for-wasm-db-storage)\n\n```typescript\ncurl --location --request GET 'http://localhost:8888/srv-applet-mgr/v0/project_config/project_01/PROJECT_SCHEMA' \\\n--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJQYXlsb2FkIjoiOTAxNjYzODYzNTI5Njc3NSIsImlzcyI6InczYnN0cmVhbSIsImV4cCI6MTY3NTE0MzA0Nn0.okRRanlER4OwZTSS60m4qdg5F4qjVWDcPys-eAJ5KkE' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n  \"tables\": [\n    {\n      \"name\": \"f_table\",\n      \"desc\": \"test table\",\n      \"cols\": [\n        {\n          \"name\": \"f_gender\",\n          \"constrains\": {\n            \"datatype\": \"UINT8\",\n            \"length\": 255,\n            \"default\": \"0\",\n            \"desc\": \"user name\"\n          }\n        }\n      ],\n      \"keys\": [\n        {\n          \"name\": \"ui_gender\",\n          \"isUnique\": true,\n          \"columnNames\": [\n            \"f_gender\"\n          ]\n        }\n      ],\n      \"withSoftDeletion\": true,\n      \"withPrimaryKey\": true\n    }\n  ]\n}'\n```\n\n```typescript\nexport { alloc } from \"@w3bstream/wasm-sdk\";\nimport { ExecSQL, QuerySQL, Log } from \"@w3bstream/wasm-sdk\";\n\nexport function start(rid: i32): i32 {\n  Log(\"start from typescript\");\n  const key = GetDataByRID(rid);\n  const v = new Map\u003cstring, i32\u003e();\n  v.set(\"int32\", 1);\n  const value = ExecSQL(`INSERT INTO \"f_table\" (f_id,f_gender) VALUES (?,?);`, [v, v]);\n  const res = QuerySQL(`SELECT * FROM \"f_table\" WHERE f_id = ?;`, [v]);\n  Log(\"wasm get value:\" + value);\n  Log(\"wasm get res:\" + res);  \n  return 0;\n}\n```\n\n## GetEnv(key:string)\n\n```typescript\nimport { GetEnv, Log } from \"@w3bstream/wasm-sdk\";\nexport { alloc } from \"@w3bstream/wasm-sdk\";\n\nexport function start(rid: i32): i32 {\n  const key = GetDataByRID(rid);\n  const value = GetEnv(key);\n  Log(\"wasm get env:\" + value);\n  return 0;\n}\n```\n\n## CallContract(chainId:i32,to:string,data:string) : string\n\n```typescript\nimport { CallContract, GetDataByRID, Log, SendTx } from \"@w3bstream/wasm-sdk\";\nimport { hexToAddress, hexToBool, hexToUtf8 } from \"@w3bstream/wasm-sdk/assembly/utility\";\n\nexport { alloc } from \"@w3bstream/wasm-sdk\";\n\nexport function start(rid: i32): i32 {\n  const message = GetDataByRID(rid);\n  Log(\"wasm received message:\" + message);\n  const ERC20Addr = \"0xa00744882684c3e4747faefd68d283ea44099d03\";\n  const balanceOfHex = CallContract(4689, ERC20Addr, `0x70a082310000000000000000000000009117f5ef4156709092f79740a97b1638ca399a00`);\n\n  Log(\"balanceOfHex:\" + balanceOfHex);\n  Log(\"balanceOfInt:\" + parseInt(balanceOfHex, 16).toString());\n\n  const symbolHex = CallContract(4689, ERC20Addr, `0x95d89b41`);\n  Log(\"symbolHex:\" + symbolHex);\n  Log(\"symbol:\" + hexToUtf8(symbolHex));\n\n  //if return type is 'bool'\n  //use hexToBool\n\n  //if return type is 'address'\n  //use hexToAddress\n  return 0;\n}\n```\n\n## Api call document\n\u003e https://github.com/machinefi/w3bstream-wasm-golang-sdk/blob/main/api.md#send-zero-knowledge-proof\n\n## Log\n\n\u003e Log(message: string)\n\n```typescript\nimport { Log } from \"@w3bstream/wasm-sdk\";\n//export alloc for w3bstream vm\nexport { alloc } from \"@w3bstream/wasm-sdk\";\n\nexport function start(rid: i32): i32 {\n  Log(\"Start from assemblyscript\");\n  const message = GetDataByRID(rid);\n  Log(\"wasm received message:\" + message);\n  return 0;\n}\n```\n\n## GenZkProof\n\u003e genZkProof(imageID: string, privateInput: string, publicInput: string, receiptType: string, eventType: string = \"result\") : string\n```typescript\nimport { Log, GetDataByRID, HTTP } from \"@w3bstream/wasm-sdk\";\nexport { alloc } from \"@w3bstream/wasm-sdk\";\nexport function start(rid: i32): i32 {\n  HTTP.genZkProof(\n    \"3145991386, 3471678490, 3632776032, 2595288688, 1478438623, 4259749138, 987879707, 1456846509\",\n    \"16\",\n    \"4,30\",\n    \"Stark\",\n    'handle_result'\n  )\n  return 0;\n}\n\nexport function handle_result(rid: i32): i32 {\n  const message = GetDataByRID(rid);\n  Log(HTTP.parseResult(message))\n  return 0;\n}\n```\n\n## ReadTx\n\u003e ReadTx(chainName: string, hash: string, eventType: string = \"result\") : string\n\n```typescript\nimport { Log, GetDataByRID, HTTP } from \"@w3bstream/wasm-sdk\";\nexport { alloc } from \"@w3bstream/wasm-sdk\";\nexport function start(rid: i32): i32 {\n  HTTP.readTx(\"iotex-testnet\", \"fcaf377ff3cc785d60c58de7e121d6a2e79e1c58c189ea8641f3ea61f7605285\")\n  return 0;\n}\n\nexport function handle_result(rid: i32): i32 {\n  const message = GetDataByRID(rid);\n  Log(HTTP.parseResult(message))\n  return 0;\n}\n```\n\n\n\n## SendTx\n\n\u003e SendTx(chainId:i32, tx: string) : string\n\n```typescript\nimport { Log, GetDataByRID, HTTP } from \"@w3bstream/wasm-sdk\";\nexport { alloc } from \"@w3bstream/wasm-sdk\";\nexport function start(rid: i32): i32 {\n  HTTP.sendTx(\"iotex-testnet\", \"default\", \"0x9117f5EF4156709092f79740a97b1638cA399A00\", \"10000000000000000000\", \"0x\")\n  return 0;\n}\n\nexport function handle_result(rid: i32): i32 {\n  const message = GetDataByRID(rid);\n  Log(HTTP.parseResult(message))\n  return 0;\n}\n```\n\n## GetDB \u0026 SetDB\n\n\u003e SetDB(key: string, value: i32)\n\n\u003e GetDB(key: string)\n\n```typescript\nimport { SetDB, Log, GetDB } from \"@w3bstream/wasm-sdk\";\nexport { alloc } from \"@w3bstream/wasm-sdk\";\n\nexport function start(rid: i32): i32 {\n  SetDB(\"wordCount\", word.length);\n  let value = GetDB(\"wordCount\");\n  Log(\"wasm get value:\" + value.toString());\n  return 0;\n}\n```\n\n\n## Build\n\n\u003e https://www.assemblyscript.org/concepts.html#special-imports\n\nThe abort method will be exposed inside w3bstream in later versions\n[issues/308](https://github.com/machinefi/w3bstream/issues/308)\n\n```typescript\nexport function abort(message: string | null, fileName: string | null, lineNumber: u32, columnNumber: u32): void {}\n```\n\npackage.json\n\n```json\n\"scripts\": {\n    \"asbuild:release\": \"asc assembly/index.ts --use abort=assembly/index/abort --target release\",\n  },\n```\n\nSome language features need support from the host environment to function, yielding a few special module imports depending on the feature set used within the module. Generated bindings provide these automatically where necessary.\n\n- function env.abort?(message: usize, fileName: usize, line: u32, column: u32): void\n\nThe respective implementations of , and can be overridden with, for example, , here redirecting calls to to a custom function in . Useful if an environment does not provide compatible implementations, or when the respective imports are not desired and custom implementations are sufficient.aborttraceseed--use abort=assembly/index/myAbortabortmyAbortassembly/index.ts\n\n## Known Issues\n\n- If the `pnpm` installation package is used, dependencies may not be correctly installed. You can use `npm` or `yarn` to install dependencies\n\n## Run examples\n\nExamples can be found in the ./examples folder.\n\nTo build an example, from the main SDK folder type:\n\n```\nnpm install\nnpm run build:\u003cexample_name\u003e\n```\n\nAvailable examples are:\n\n- `abort` - Tests the call of the `abort` function on the W3bstream VM side by calling `assert` in your applet.\n- `click2earn` - a simple applet that mints ERC20 tokens every 5 \"click\" messages are received\n- `env` - shows how to retrieve env variable for the parent project (a defined in the project's settings on dev.w3bstream.com)\n- `erc20_mint` - a basic example that shows how to mint ERC20 tokens from an applet according to the info included in the data message\n- `json` - shows how to parse a data message and extract specific fields\n- `sql` - shows how to insert and query data from W3bstreams database using SQL\n- `token_distribute` - another basic example that sends ERC20 tokens to a wallet\n- `vm` - another example of using `assert` in your applet\n- `word_count` - counts the number of words included in a message payload and shows how to save it in W3bstream's key/value storage.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachinefi%2Fw3bstream-wasm-assemblyscript-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmachinefi%2Fw3bstream-wasm-assemblyscript-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachinefi%2Fw3bstream-wasm-assemblyscript-sdk/lists"}