{"id":13566110,"url":"https://github.com/CosmWasm/cosmwasm","last_synced_at":"2025-04-03T23:31:10.483Z","repository":{"id":37206016,"uuid":"212116761","full_name":"CosmWasm/cosmwasm","owner":"CosmWasm","description":"Framework for building smart contracts in Wasm for the Cosmos SDK","archived":false,"fork":false,"pushed_at":"2024-11-12T15:07:41.000Z","size":22185,"stargazers_count":1073,"open_issues_count":75,"forks_count":336,"subscribers_count":38,"default_branch":"main","last_synced_at":"2024-11-15T09:52:14.199Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.cosmwasm.com/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CosmWasm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG-pre1.0.0.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-01T14:25:20.000Z","updated_at":"2024-11-12T15:00:17.000Z","dependencies_parsed_at":"2023-02-16T07:46:13.908Z","dependency_job_id":"4d2cd32c-0bad-46d0-be01-bdcc85aead80","html_url":"https://github.com/CosmWasm/cosmwasm","commit_stats":{"total_commits":4203,"total_committers":44,"mean_commits":95.52272727272727,"dds":0.5291458482036641,"last_synced_commit":"54e3e78f13503043e685fb639652420e7d5ff818"},"previous_names":[],"tags_count":172,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmWasm%2Fcosmwasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmWasm%2Fcosmwasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmWasm%2Fcosmwasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CosmWasm%2Fcosmwasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CosmWasm","download_url":"https://codeload.github.com/CosmWasm/cosmwasm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246706673,"owners_count":20820785,"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-08-01T13:02:02.292Z","updated_at":"2025-04-03T23:31:05.466Z","avatar_url":"https://github.com/CosmWasm.png","language":"Rust","funding_links":[],"categories":["General Resources","\u003ca name=\"wasmer\"\u003e\u003c/a\u003e[Wasmer](https://github.com/wasmerio/wasmer) \u003csup\u003e[top⇈](#contents)\u003c/sup\u003e","others","Virtual Machines","Rust","Overview","Cryptocurrencies"],"sub_categories":["Terminal Block Explorers","External Modules"],"readme":"# CosmWasm\n\n[![CircleCI](https://circleci.com/gh/CosmWasm/cosmwasm/tree/main.svg?style=shield)](https://circleci.com/gh/CosmWasm/cosmwasm/tree/main)\n\n**WebAssembly Smart Contracts for the Cosmos SDK.**\n\n## Packages\n\nThe following packages are maintained here:\n\n| Crate           | Usage                | Download                                                                                                                         | Docs                                                                                  | Coverage                                         |\n| --------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------ |\n| cosmwasm-crypto | Internal only        | [![cosmwasm-crypto on crates.io](https://img.shields.io/crates/v/cosmwasm-crypto.svg)](https://crates.io/crates/cosmwasm-crypto) | [![Docs](https://docs.rs/cosmwasm-crypto/badge.svg)](https://docs.rs/cosmwasm-crypto) | [![Coverage][cov-badge-crypto]][cov-link-crypto] |\n| cosmwasm-derive | Internal only        | [![cosmwasm-derive on crates.io](https://img.shields.io/crates/v/cosmwasm-derive.svg)](https://crates.io/crates/cosmwasm-derive) | [![Docs](https://docs.rs/cosmwasm-derive/badge.svg)](https://docs.rs/cosmwasm-derive) | [![Coverage][cov-badge-derive]][cov-link-derive] |\n| cosmwasm-schema | Contract development | [![cosmwasm-schema on crates.io](https://img.shields.io/crates/v/cosmwasm-schema.svg)](https://crates.io/crates/cosmwasm-schema) | [![Docs](https://docs.rs/cosmwasm-schema/badge.svg)](https://docs.rs/cosmwasm-schema) | [![Coverage][cov-badge-schema]][cov-link-schema] |\n| cosmwasm-core   | Internal only        | [![cosmwasm-core on crates.io](https://img.shields.io/crates/v/cosmwasm-core.svg)](https://crates.io/crates/cosmwasm-core)       | [![Docs](https://docs.rs/cosmwasm-core/badge.svg)](https://docs.rs/cosmwasm-core)     | [![Coverage][cov-badge-core]][cov-link-core]     |\n| cosmwasm-std    | Contract development | [![cosmwasm-std on crates.io](https://img.shields.io/crates/v/cosmwasm-std.svg)](https://crates.io/crates/cosmwasm-std)          | [![Docs](https://docs.rs/cosmwasm-std/badge.svg)](https://docs.rs/cosmwasm-std)       | [![Coverage][cov-badge-std]][cov-link-std]       |\n| cosmwasm-vm     | Host environments    | [![cosmwasm-vm on crates.io](https://img.shields.io/crates/v/cosmwasm-vm.svg)](https://crates.io/crates/cosmwasm-vm)             | [![Docs](https://docs.rs/cosmwasm-vm/badge.svg)](https://docs.rs/cosmwasm-vm)         | [![Coverage][cov-badge-vm]][cov-link-vm]         |\n| cosmwasm-check  | Contract development | [![cosmwasm-check on crates.io](https://img.shields.io/crates/v/cosmwasm-check.svg)](https://crates.io/crates/cosmwasm-check)    | `cosmwasm-check -h`                                                                   | N/A                                              |\n\n[cosmwasm-storage](https://crates.io/crates/cosmwasm-storage) is no longer\nmaintained and has been dropped in favor of\n[cw-storage-plus](https://github.com/CosmWasm/cw-storage-plus).\n\n[cov-badge-crypto]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-crypto\n[cov-badge-derive]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-derive\n[cov-badge-schema]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-schema\n[cov-badge-core]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-core\n[cov-badge-std]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-std\n[cov-badge-vm]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/branch/main/graph/badge.svg?flag=cosmwasm-vm\n[cov-link-crypto]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/tree/main/packages/crypto\n[cov-link-derive]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/tree/main/packages/derive\n[cov-link-schema]:\n  https://codecov.io/gh/CosmWasm/cosmwasm/tree/main/packages/schema\n[cov-link-core]: https://codecov.io/gh/CosmWasm/cosmwasm/tree/main/packages/core\n[cov-link-std]: https://codecov.io/gh/CosmWasm/cosmwasm/tree/main/packages/std\n[cov-link-vm]: https://codecov.io/gh/CosmWasm/cosmwasm/tree/main/packages/vm\n\n## Overview\n\nTo get that contract to interact with a system needs many moving parts. To get\noriented, here is a list of the various components of the CosmWasm ecosystem:\n\n**Standard library:**\n\nThis code is compiled into Wasm bytecode as part of the smart contract.\n\n- [cosmwasm-std](https://github.com/CosmWasm/cosmwasm/tree/main/packages/std) -\n  A crate in this workspace. Provides the bindings and all imports needed to\n  build a smart contract.\n- [cw-storage-plus](https://github.com/CosmWasm/cw-storage-plus) - A crate which\n  provides convenience helpers for interacting with storage with powerful types\n  supporting composite primary keys, secondary indexes, automatic snapshotting,\n  and more. This is used in most modern contracts.\n\n**Building contracts:**\n\n- [cosmwasm-template](https://github.com/CosmWasm/cosmwasm-template) - A\n  starter-pack to get you quickly building your custom contract compatible with\n  the cosmwasm system.\n- [cosmwasm-plus](https://github.com/CosmWasm/cosmwasm-plus) - Some sample\n  contracts for use and inspiration. These provide usable primitives and\n  interfaces for many use cases, such as fungible tokens, NFTs, multisigs,\n  governance votes, staking derivatives, and more. Look in `packages` for docs\n  on the various standard interfaces, and `contracts` for the implementations.\n  Please submit your contract or interface via PR.\n- [rust-optimizer](https://github.com/cosmwasm/rust-optimizer) - A docker image\n  and scripts to take your Rust code and produce the smallest possible Wasm\n  output, deterministically. This is designed both for preparing contracts for\n  deployment as well as validating that a given deployed contract is based on\n  some given source code, allowing a\n  [similar contract verification algorithm](https://medium.com/coinmonks/how-to-verify-and-publish-on-etherscan-52cf25312945)\n  as Etherscan.\n\n  Building locally instead of using the docker image can\n  [leak some information about the directory structure of your system](https://github.com/CosmWasm/cosmwasm/issues/1918)\n  and makes the build non-reproducible.\n\n- [serde-json-wasm](https://github.com/CosmWasm/serde-json-wasm) - A custom json\n  library, forked from `serde-json-core`. This provides an interface similar to\n  `serde-json`, but without any floating-point instructions (non-deterministic)\n  and producing builds around 40% of the code size.\n\n**Executing contracts:**\n\n- [cosmwasm-vm](https://github.com/CosmWasm/cosmwasm/tree/main/packages/vm) - A\n  crate in this workspace. Uses the [wasmer](https://github.com/wasmerio/wasmer)\n  engine to execute a given smart contract. Also contains code for gas metering,\n  storing, and caching wasm artifacts.\n- [wasmvm](https://github.com/CosmWasm/wasmvm) - High-level go bindings to all\n  the power inside `cosmwasm-vm`. Easily allows you to upload, instantiate and\n  execute contracts, making use of all the optimizations and caching available\n  inside `cosmwasm-vm`.\n- [wasmd](https://github.com/CosmWasm/wasmd) - A basic Cosmos SDK app to host\n  WebAssembly smart contracts. It can be run as is, or you can import the\n  `x/wasm` module from it and use it in your blockchain. It is designed to be\n  imported and customized for other blockchains, rather than forked.\n- [cosmwasm-check](https://github.com/CosmWasm/cosmwasm/tree/main/packages/check) -\n  A CLI tool and a crate in this workspace. Used to verify a Wasm binary is a\n  CosmWasm smart contract suitable for uploading to a blockchain with a given\n  set of capabilities.\n\n## Creating a Smart Contract\n\nYou can see some examples of contracts under the `contracts` directory, which\nyou can look at. They are simple and self-contained, primarily meant for testing\npurposes, but that also makes them easier to understand.\n\nYou can also look at [cw-plus](https://github.com/CosmWasm/cw-plus) for examples\nand inspiration on more production-like contracts and also how we call one\ncontract from another. If you are working on DeFi or Tokens, please look at the\n`cw20`, `cw721` and/or `cw1155` packages that define standard interfaces as\nanalogues to some popular ERC designs. (`cw20` is also inspired by `erc777`).\n\nIf you want to get started building your own contract, the simplest way is to go\nto the [cosmwasm-template](https://github.com/CosmWasm/cosmwasm-template)\nrepository and follow the instructions. This will give you a simple contract\nalong with tests, and a properly configured build environment. From there you\ncan edit the code to add your desired logic and publish it as an independent\nrepo.\n\nWe also recommend you review our [documentation site](https://book.cosmwasm.com)\nwhich contains a few tutorials to guide you in building your first contracts.\nYou can find past recordings of hackathon / conference workshops and\npresentations on our [YouTube channel](https://www.youtube.com/@CosmWasm), or\n[join our Discord server](https://chat.cosmwasm.com) to ask for help.\n\n## Minimum Supported Rust Version (MSRV)\n\nSee [Minimum Supported Rust Version (MSRV)](./docs/MSRV.md).\n\n## API entry points\n\nWebAssembly contracts are basically black boxes. They have no default entry\npoints, and no access to the outside world by default. To make them useful, we\nneed to add a few elements.\n\nIf you haven't worked with WebAssembly before, please read an overview on\n[how to create imports and exports](./EntryPoints.md) in general.\n\n### Exports\n\nThe required exports provided by the cosmwasm smart contract are:\n\n```rust\n// signal for 1.0 compatibility\nextern \"C\" fn interface_version_8() -\u003e () {}\n\n// copy memory to/from host, so we can pass in/out Vec\u003cu8\u003e\nextern \"C\" fn allocate(size: usize) -\u003e u32;\nextern \"C\" fn deallocate(pointer: u32);\n\n// creates an initial state of a contract with a configuration send in the argument msg_ptr\nextern \"C\" fn instantiate(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -\u003e u32;\n```\n\nContracts may also implement one or more of the following to extend their\nfunctionality:\n\n```rust\n// modify the state of the contract\nextern \"C\" fn execute(env_ptr: u32, info_ptr: u32, msg_ptr: u32) -\u003e u32;\n\n// query the state of the contract\nextern \"C\" fn query(env_ptr: u32, msg_ptr: u32) -\u003e u32;\n\n// in-place contract migrations\nextern \"C\" fn migrate(env_ptr: u32, msg_ptr: u32) -\u003e u32;\n\n// support submessage callbacks\nextern \"C\" fn reply(env_ptr: u32, msg_ptr: u32) -\u003e u32;\n\n// expose privileged entry points to Cosmos SDK modules, not external accounts\nextern \"C\" fn sudo(env_ptr: u32, msg_ptr: u32) -\u003e u32;\n\n// and to write an IBC application as a contract, implement these:\nextern \"C\" fn ibc_channel_open(env_ptr: u32, msg_ptr: u32) -\u003e u32;\nextern \"C\" fn ibc_channel_connect(env_ptr: u32, msg_ptr: u32) -\u003e u32;\nextern \"C\" fn ibc_channel_close(env_ptr: u32, msg_ptr: u32) -\u003e u32;\nextern \"C\" fn ibc_packet_receive(env_ptr: u32, msg_ptr: u32) -\u003e u32;\nextern \"C\" fn ibc_packet_ack(env_ptr: u32, msg_ptr: u32) -\u003e u32;\nextern \"C\" fn ibc_packet_timeout(env_ptr: u32, msg_ptr: u32) -\u003e u32;\n```\n\n`allocate`/`deallocate` allow the host to manage data within the Wasm VM. If\nyou're using Rust, you can implement them by simply\n[re-exporting them from cosmwasm::exports](https://github.com/CosmWasm/cosmwasm/blob/v0.6.3/contracts/hackatom/src/lib.rs#L5).\n`instantiate`, `execute` and `query` must be defined by your contract.\n\n### Imports\n\nThe imports provided to give the contract access to the environment are:\n\n```rust\n// This interface will compile into required Wasm imports.\n// A complete documentation of those functions is available in the VM that provides them:\n// https://github.com/CosmWasm/cosmwasm/blob/v1.0.0-beta/packages/vm/src/instance.rs#L89-L206\nextern \"C\" {\n    fn db_read(key: u32) -\u003e u32;\n    fn db_write(key: u32, value: u32);\n    fn db_remove(key: u32);\n\n    // scan creates an iterator, which can be read by consecutive next() calls\n    #[cfg(feature = \"iterator\")]\n    fn db_scan(start_ptr: u32, end_ptr: u32, order: i32) -\u003e u32;\n    #[cfg(feature = \"iterator\")]\n    fn db_next(iterator_id: u32) -\u003e u32;\n\n    fn addr_validate(source_ptr: u32) -\u003e u32;\n    fn addr_canonicalize(source_ptr: u32, destination_ptr: u32) -\u003e u32;\n    fn addr_humanize(source_ptr: u32, destination_ptr: u32) -\u003e u32;\n\n    /// Verifies message hashes against a signature with a public key, using the\n    /// secp256k1 ECDSA parametrization.\n    /// Returns 0 on verification success, 1 on verification failure, and values\n    /// greater than 1 in case of error.\n    fn secp256k1_verify(message_hash_ptr: u32, signature_ptr: u32, public_key_ptr: u32) -\u003e u32;\n\n    fn secp256k1_recover_pubkey(\n        message_hash_ptr: u32,\n        signature_ptr: u32,\n        recovery_param: u32,\n    ) -\u003e u64;\n\n    /// Verifies message hashes against a signature with a public key, using the\n    /// secp256r1 ECDSA parametrization.\n    /// Returns 0 on verification success, 1 on verification failure, and values\n    /// greater than 1 in case of error.\n    fn secp256r1_verify(message_hash_ptr: u32, signature_ptr: u32, public_key_ptr: u32) -\u003e u32;\n\n    fn secp256r1_recover_pubkey(\n      message_hash_ptr: u32,\n      signature_ptr: u32,\n      recovery_param: u32,\n    ) -\u003e u64;\n\n    /// Verifies a message against a signature with a public key, using the\n    /// ed25519 EdDSA scheme.\n    /// Returns 0 on verification success, 1 on verification failure, and values\n    /// greater than 1 in case of error.\n    fn ed25519_verify(message_ptr: u32, signature_ptr: u32, public_key_ptr: u32) -\u003e u32;\n\n    /// Verifies a batch of messages against a batch of signatures and public keys, using the\n    /// ed25519 EdDSA scheme.\n    /// Returns 0 on verification success, 1 on verification failure, and values\n    /// greater than 1 in case of error.\n    fn ed25519_batch_verify(messages_ptr: u32, signatures_ptr: u32, public_keys_ptr: u32) -\u003e u32;\n\n    /// Writes a debug message (UFT-8 encoded) to the host for debugging purposes.\n    /// The host is free to log or process this in any way it considers appropriate.\n    /// In production environments it is expected that those messages are discarded.\n    fn debug(source_ptr: u32);\n\n    /// Executes a query on the chain (import). Not to be confused with the\n    /// query export, which queries the state of the contract.\n    fn query_chain(request: u32) -\u003e u32;\n}\n```\n\n(from\n[imports.rs](https://github.com/CosmWasm/cosmwasm/blob/main/packages/std/src/imports.rs))\n\nYou could actually implement a WebAssembly module in any language, and as long\nas you implement these functions, it will be interoperable, given the JSON data\npassed around is in the proper format.\n\nNote that these u32 pointers refer to `Region` instances, containing the offset\nand length of some Wasm memory, to allow for safe access between the caller and\nthe contract:\n\n```rust\n/// Describes some data allocated in Wasm's linear memory.\n/// A pointer to an instance of this can be returned over FFI boundaries.\n///\n/// This struct is crate internal since the cosmwasm-vm defines the same type independently.\n#[repr(C)]\npub struct Region {\n    /// The beginning of the region expressed as bytes from the beginning of the linear memory\n    pub offset: u32,\n    /// The number of bytes available in this region\n    pub capacity: u32,\n    /// The number of bytes used in this region\n    pub length: u32,\n}\n```\n\n(from\n[memory.rs](https://github.com/CosmWasm/cosmwasm/blob/main/packages/std/src/memory.rs))\n\n## Implementing the Smart Contract\n\nIf you followed the [instructions above](#Creating-a-smart-contract), you should\nhave a runable smart contract. You may notice that all of the Wasm exports are\ntaken care of by `lib.rs`, which you shouldn't need to modify. What you need to\ndo is simply look in `contract.rs` and implement `instantiate` and `execute`\nfunctions, defining your custom `InstantiateMsg` and `ExecuteMsg` structs for\nparsing your custom message types (as json):\n\n```rust\n#[entry_point]\npub fn instantiate(\n  deps: DepsMut,\n  env: Env,\n  info: MessageInfo,\n  msg: InstantiateMsg,\n) -\u003e Result\u003cResponse, ContractError\u003e {}\n\n#[entry_point]\npub fn execute(\n  deps: DepsMut,\n  env: Env,\n  info: MessageInfo,\n  msg: ExecuteMsg,\n) -\u003e Result\u003cResponse, ContractError\u003e {}\n\n#[entry_point]\npub fn query(deps: Deps, env: Env, msg: QueryMsg) -\u003e Result\u003cBinary, ContractError\u003e {}\n\n#[entry_point]\npub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -\u003e Result\u003cResponse, ContractError\u003e {}\n```\n\nThe low-level `db_read` and `db_write` imports are nicely wrapped for you by a\n`Storage` implementation (which can be swapped out between real Wasm code and\ntest code). This gives you a simple way to read and write data to a custom\nsub-database that this contract can safely write to as it wants. It's up to you\nto determine which data you want to store here:\n\n```rust\n/// Storage provides read and write access to a persistent storage.\n/// If you only want to provide read access, provide `\u0026Storage`\npub trait Storage {\n    /// Returns None when key does not exist.\n    /// Returns Some(Vec\u003cu8\u003e) when key exists.\n    ///\n    /// Note: Support for differentiating between a non-existent key and a key with empty value\n    /// is not great yet and might not be possible in all backends. But we're trying to get there.\n    fn get(\u0026self, key: \u0026[u8]) -\u003e Option\u003cVec\u003cu8\u003e\u003e;\n\n    #[cfg(feature = \"iterator\")]\n    /// Allows iteration over a set of key/value pairs, either forwards or backwards.\n    ///\n    /// The bound `start` is inclusive and `end` is exclusive.\n    ///\n    /// If `start` is lexicographically greater than or equal to `end`, an empty range is described, no matter of the order.\n    fn range\u003c'a\u003e(\n        \u0026'a self,\n        start: Option\u003c\u0026[u8]\u003e,\n        end: Option\u003c\u0026[u8]\u003e,\n        order: Order,\n    ) -\u003e Box\u003cdyn Iterator\u003cItem = Record\u003e + 'a\u003e;\n\n    fn set(\u0026mut self, key: \u0026[u8], value: \u0026[u8]);\n\n    /// Removes a database entry at `key`.\n    ///\n    /// The current interface does not allow to differentiate between a key that existed\n    /// before and one that didn't exist. See https://github.com/CosmWasm/cosmwasm/issues/290\n    fn remove(\u0026mut self, key: \u0026[u8]);\n}\n```\n\n(from\n[traits.rs](https://github.com/CosmWasm/cosmwasm/blob/main/packages/std/src/traits.rs))\n\n## Testing the Smart Contract (rust)\n\nFor quick unit tests and useful error messages, it is often helpful to compile\nthe code using native build system and then test all code except for the\n`extern \"C\"` functions (which should just be small wrappers around the real\nlogic).\n\nIf you have non-trivial logic in the contract, please write tests using rust's\nstandard tooling. If you run `cargo test`, it will compile into native code\nusing the `debug` profile, and you get the normal test environment you know and\nlove. Notably, you can add plenty of requirements to `[dev-dependencies]` in\n`Cargo.toml` and they will be available for your testing joy. As long as they\nare only used in `#[cfg(test)]` blocks, they will never make it into the\n(release) Wasm builds and have no overhead on the production artifact.\n\nNote that for tests, you can use the `MockStorage` implementation which gives a\ngeneric in-memory hashtable in order to quickly test your logic. You can see a\n[simple example of how to write a test](https://github.com/CosmWasm/cosmwasm/blob/81b6702d3994c8c34fb51c53176993b7e672860b/contracts/hackatom/src/contract.rs#L70-L88)\nin our sample contract.\n\n## Testing the Smart Contract (wasm)\n\nYou may also want to ensure the compiled contract interacts with the environment\nproperly. To do so, you will want to create a canonical release build of the\n`\u003ccontract\u003e.wasm` file and then write tests with the same VM tooling we will use\nin production. This is a bit more complicated but we added some tools to help in\n[cosmwasm-vm](https://github.com/CosmWasm/cosmwasm/tree/main/packages/vm) which\ncan be added as a `dev-dependency`.\n\nYou will need to first compile the contract using `cargo wasm`, then load this\nfile in the integration tests. Take a\n[look at the sample tests](https://github.com/CosmWasm/cosmwasm/blob/main/contracts/hackatom/tests/integration.rs)\nto see how to do this... it is often quite easy to port a unit test to an\nintegration test.\n\n## Production Builds\n\nThe above build process (`cargo wasm`) works well to produce wasm output for\ntesting. However, it is quite large, around 1.5 MB likely, and not suitable for\nposting to the blockchain. Furthermore, it is very helpful if we have\nreproducible build step so others can prove the on-chain wasm code was generated\nfrom the published rust code.\n\nFor that, we have a separate repo,\n[rust-optimizer](https://github.com/CosmWasm/rust-optimizer) that provides a\n[docker image](https://hub.docker.com/r/CosmWasm/optimizer/tags) for building.\nFor more info, look at\n[rust-optimizer README](https://github.com/CosmWasm/rust-optimizer/blob/master/README.md#usage),\nbut the quickstart guide is:\n\n```sh\ndocker run --rm -v \"$(pwd)\":/code \\\n  --mount type=volume,source=\"$(basename \"$(pwd)\")_cache\",target=/target \\\n  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \\\n  cosmwasm/optimizer:0.15.0\n```\n\nIt will output a highly size-optimized build as `contract.wasm` in `$CODE`. With\nour example contract, the size went down to 126kB (from 1.6MB from\n`cargo wasm`). If we didn't use serde-json, this would be much smaller still...\n\n## Benchmarking\n\nYou may want to compare how long the contract takes to run inside the Wasm VM\ncompared to in native rust code, especially for computationally intensive code,\nlike hashing or signature verification.\n\n**TODO** add instructions\n\n## Developing\n\nThe ultimate auto-updating guide to building this project is the CI\nconfiguration in `.circleci/config.yml`.\n\nFor manually building this repo locally during development, here are a few\ncommands. They assume you use a stable Rust version by default and have a\nnightly toolchain installed as well.\n\n**Workspace**\n\n```sh\n# Compile and lint\n./devtools/check_workspace.sh\n\n# Run tests\n./devtools/test_workspace.sh\n```\n\n**Contracts**\n\n| Step | Description                      | Command                                |\n| ---- | -------------------------------- | -------------------------------------- |\n| 1    | fast checks, rebuilds lock files | `./devtools/check_contracts_fast.sh`   |\n| 2    | medium fast checks               | `./devtools/check_contracts_medium.sh` |\n| 3    | slower checks                    | `./devtools/check_contracts_full.sh`   |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCosmWasm%2Fcosmwasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCosmWasm%2Fcosmwasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCosmWasm%2Fcosmwasm/lists"}