{"id":19259271,"url":"https://github.com/hyperweb-io/cw-simulate","last_synced_at":"2025-04-21T16:30:50.151Z","repository":{"id":60720224,"uuid":"531933743","full_name":"hyperweb-io/cw-simulate","owner":"hyperweb-io","description":"Mock blockchain environment for simulating CosmWasm interactions","archived":false,"fork":false,"pushed_at":"2023-03-15T05:18:51.000Z","size":2475,"stargazers_count":30,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T12:48:08.697Z","etag":null,"topics":["cosmwasm","javascript","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://cwsimulate.terran.one","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/hyperweb-io.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,"governance":null}},"created_at":"2022-09-02T13:20:05.000Z","updated_at":"2025-01-18T01:32:07.000Z","dependencies_parsed_at":"2023-02-14T07:00:30.532Z","dependency_job_id":"9fbf3b5b-d1d0-4eca-b50f-7f50b7aacb3b","html_url":"https://github.com/hyperweb-io/cw-simulate","commit_stats":null,"previous_names":["terran-one/cw-simulate","hyperweb-io/cw-simulate"],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcw-simulate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcw-simulate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcw-simulate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperweb-io%2Fcw-simulate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperweb-io","download_url":"https://codeload.github.com/hyperweb-io/cw-simulate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250090697,"owners_count":21373235,"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":["cosmwasm","javascript","wasm","webassembly"],"created_at":"2024-11-09T19:15:54.501Z","updated_at":"2025-04-21T16:30:49.567Z","avatar_url":"https://github.com/hyperweb-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `cw-simulate`\n\nThis package combines `cosmwasm-vm-js` with additional abstractions and state management to\nmore accurately simulate the effects of CosmWasm contracts on the blockchain environments on which\nthey are hosted.\n\n## Features\n\n- configure multiple host chain environments with chain-specific settings / state\n- multiple simultaneous contract instances can exist per chain\n- chain modules can be simulated through custom user code\n- extensible for further instrumentation via custom middlewares\n\n\n## Getting Started\n\nImport the `cw-simulate` library from NPM in your `package.json`.\n\n```bash\n$ npm install -S @terran-one/cw-simulate\n```\n\nIf you're using Yarn:\n\n```bash\n$ yarn add @terran-one/cw-simulate\n```\n\n## Usage\n\n1. Create a `CWSimulateApp` object - this is a simulation environment describing a single chain.\n2. As needed, per chain:\n   - Upload the WASM bytecode using `App.wasm.create`. This will register a new `codeId` to reference the uploaded contract code.\n   - Create a new contract instance using `App.wasm.instantiateContract`, passing in the `codeId` generated in the previous step.\n   - From the response, retrieve the `contractAddress` to refer to the contract instance.\n  - You can now run `execute` and `query` messages against the instance, and they should work as expected.\n\n### Example\n\nThe following example creates a chain, instantiates a contract on it, and performs an `execute` and `query`.\n\n```javascript\nimport { CWSimulateApp } from '@terran-one/cw-simulate';\nimport { readFileSync } from 'fs';\n\nconst sender = 'terra1hgm0p7khfk85zpz5v0j8wnej3a90w709vhkdfu';\nconst funds = [];\nconst wasmBytecode = readFileSync('cw-template.wasm');\n\nconst app = new CWSimulateApp({\n  chainId: 'phoenix-1',\n  bech32Prefix: 'terra'\n});\n\n// import the wasm bytecode\nconst codeId = app.wasm.create(sender, wasmBytecode);\n\n// instantiate the contract\nlet result = await app.wasm.instantiateContract(sender, funds, codeId, { count: 0 });\nconsole.log('instantiateContract:', result.constructor.name, JSON.stringify(result, null, 2));\n\n// pull out the contract address\nconst contractAddress = result.val.events[0].attributes[0].value;\n\n// execute the contract\nresult = await app.wasm.executeContract(sender, funds, contractAddress, { increment: {} });\nconsole.log('executeContract:', result.constructor.name, JSON.stringify(result, null, 2));\n\n// query the contract\nresult = await app.wasm.query(contractAddress, { get_count: {} });\nconsole.log('query:', result.constructor.name, JSON.stringify(result, null, 2));\n```\n\n## Using with Vue.js and vite\n\nVite doesn't include shims for Node variables like Webpack 4 does, and cw-simulate currently relies on these. The following workaround exists:\n\n1. Add the `buffer` package (`npm add buffer`)\n2. Add the following to your `index.html` (inside the `body` tag, before your other js imports):\n```html\n\u003cscript\u003e\n  window.global = window;\n\u003c/script\u003e\n\u003cscript type=\"module\"\u003e\n  import {Buffer} from \"buffer\";\n  window.Buffer = Buffer;\n\u003c/script\u003e\n```\n\nSee [this github issue](https://github.com/vitejs/vite/issues/2618) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperweb-io%2Fcw-simulate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperweb-io%2Fcw-simulate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperweb-io%2Fcw-simulate/lists"}