# Exploring NEAR's VM.require Feature ## Introduction to VM.require NEAR's VM introduces `VM.require`, a pivotal feature in its open web development environment. Initially a beta feature in version 2.2.0, it has since stabilized in version 2.5.0. VM.require enables builders to leverage SDKs in their components easily. It differs from a Widget in that it returns data which may be null initially, unlike a Widget which returns a Loading widget during data fetches. ## Understanding VM.require `VM.require(<src>)` is a new API that retrieves a module's source from the Social DB, executes it, and returns the results. The `src` argument specifies the module's source code path and can include the source version by incorporating the blockHeight. For example, `VM.require("mob.near/widget/Module.Abc@91698491")` retrieves the source at a specific block height. ## Examples ### Module: ``` function Magic(props) { return <div>Magic: {props.children}</div>; } return { Magic }; ``` ### Widget: ``` const { Magic } = VM.require("mob.near/widget/Module.Magic"); return <Magic>Hello World</Magic>; ``` [GitHub Pull Request #61 introduces this feature](https://github.com/NearSocial/VM/pull/65) ## Real-world Usage An example in practice can be found in the [sdks.near/widget/SDKs.Verifiers.Lens](https://near.org/near/widget/ComponentDetailsPage?src=sdks.near/widget/SDKs.Verifiers.Lens) component leveraging two abstracted classes: ``` const EthereumSigner = VM.require(`sdks.near/widget/SDKs.EthereumSigner.Main`); const LensSDK = VM.require(`mattb.near/widget/LensSDKRequire`); ``` The `VM.require` function in the provided code is used to import specific modules, `EthereumSigner` and `LensSDK`, into the component execution environment. The `EthereumSigner` module, once imported, is utilised in various parts of the `LensVerifier` class to handle Ethereum-based cryptographic operations like signing and verifying messages. This usage signifies how NEAR's bOS can integrate external blockchain functionalities (such as those from Ethereum) seamlessly, showcasing interoperability and the ability to leverage different blockchains within a single platform. ## Historical Context and Relevant Links This feature was introduced and implemented by [evgenykuzyakov](https://github.com/evgenykuzyakov) a.k.a. @mob.near and can be traced in the following GitHub resources: - Introduction: [GitHub Pull Request #61](https://github.com/NearSocial/VM/pull/61) - Implementation: [NEAR VM Changelog 2.2.0](https://github.com/NearSocial/VM/blob/master/CHANGELOG.md#220) ## Issues and Pull Requests - [Release 2.2.0](https://github.com/NearSocial/VM/pull/65) - [Feature: modules #17](https://github.com/NearSocial/VM/issues/17) - [Updating state in a widget breaks VM.require #88](https://github.com/NearSocial/VM/issues/88) - [Accesses vm instance map #89](https://github.com/NearSocial/VM/pull/89) - [Fix VM.require 2.4.1 #117](https://github.com/NearSocial/VM/pull/117) - [Introduce useCallback and useMemo #118](https://github.com/NearSocial/VM/pull/118) - [Synchronous Block for VM.requires #135](https://github.com/NearSocial/VM/issues/135) - [VM.require method drops error #137](https://github.com/NearSocial/VM/issues/137) - [Release 2.5.0 #142](https://github.com/NearSocial/VM/pull/142) Explore the NEAR Social's GitHub for more insights into `VM.require` and its key role in the creation of modules and SDKs on NEAR's bOS #build #documentation