🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

cosmwasm-vm

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cosmwasm-vm

**THIS IS STILL UNDER DEVELOPMENT! Contributions are welcome.**

0.1.0
latest
npm
Version published
Weekly downloads
3
50%
Maintainers
1
Weekly downloads
 
Created
Source

Run CosmWasm in JavaScript

THIS IS STILL UNDER DEVELOPMENT! Contributions are welcome.

NOTE: This was built for Terra-specific applications and thus is only supported for CosmWasm v0.16. However, this implementation probably can be easily adapted to support CosmWasm v1.0+.

This package implements a pure JavaScript (no Rust bindings / WASM needed) VM capable of executing compiled CosmWasm .wasm binaries in environments such as Node.js and compatible web browsers.

Setup

Add the cosmwasm-vm package as a dependency in your package.json.

npm install -S cosmwasm-vm

or

yarn add cosmwasm-vm

Usage

Please refer to the test in this repository for an example. I include a test contract based on cosmwasm/cw-template that has been augmented with additional ExecuteMsg variants for testing the various WASM imports.

yarn
yarn test
import { CosmWasmVM } from '../src';
import { readFileSync } from 'fs';

const wasm_byte_code = readFileSync('./cosmwasm_vm_test.wasm');
const vm = new CosmWasmVM(wasm_byte_code);

const mock_env = {
  block: {
    height: 1,
    time: '2000000000',
    chain_id: 'columbus-5',
  },
  contract: {
    address: 'contract',
  },
};

const mock_info = {
  sender: 'sender',
  funds: [],
};

describe('CosmWasmVM', () => {
  it('instantiates', () => {
    let res = vm.instantiate(mock_env, mock_info, { count: 20 });
    console.log(res.json);
    console.log(vm.store);
  });

  it('execute', () => {
    let res = vm.instantiate(mock_env, mock_info, { count: 20 });
    res = vm.execute(mock_env, mock_info, { increment: {} });
    console.log(res.json);
    console.log(vm.store);
  });
});

FAQs

Package last updated on 11 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts