📓
SANDSHREWサンド
  • Welcome to Sandshrew
    • What is SANDSHREWサンド ?
    • Getting Started
  • Sandshrew Namespaces
    • ord (inscriptions/runes)
    • esplora (Block Explorer APIs)
    • btc (Standard Bitcoin RPC)
    • Multicall
    • Runes
  • Metashrew
    • What is METASHREW?
  • Metashrew Open Source Repositories
    • metashrew
    • metashrew-cli
    • metashrew-view-rs
    • metashrew-as
    • metashrew-ord
    • metashrew-runes
  • Important Links
    • Discord
    • GitHub
    • sandshrew.io
Powered by GitBook
On this page
  • metashrew-cli
  • Install
  • Usage
  • Testing
  1. Metashrew Open Source Repositories

metashrew-cli

PreviousmetashrewNextmetashrew-view-rs

metashrew-cli

Scaffold WASM builds that can run in the metashrew runtime.

Install

git clone https://github.com/sandshrewmetaprotocols/metashrew-cli
cd metashrew-cli
npm install -g metashrew-cli

Usage

As an example, we will scaffold a metaprotocol that implements DNS on Bitcoin:

metashrew-cli new dns-on-bitcoin

Once this completes, you will have a ./dns-on-bitcoin directory that is fully installed and can execute the included scripts.

cd dns-on-bitcoin
yarn build

The build outputs a ./build/release.wasm which can be run directly in metashrew via its --indexer flag.

Find metashrew here:

The boilerplate simply imports metashrew-as which you can find here:

Edit the entrypoint _start which can be found in ./assembly/index.ts

Metaprotocols built with metashrew-cli use AssemblyScript as a compiler. This is the same compiler used for building subgraphs, for developers coming from Ethereum development. Refer to the AssemblyScript docs here:

You don't have to build metaprotocls in AssemblyScript alone. The WASM builds can link to Rust sources built with no_std with wasm-pack or similar WASM build crates.

Anything that compiles to WASM can link to the binaries produced with this CLI.

Testing

The boilerplate project generated by this CLI includes metashrew-test which is a mock runtime for metashrew. This allows you to write test cases with mock block data and check your key-value pairs after program run. More complex testing can be accomplished using this IndexerProgram class.

To run the included tests, execute:

yarn test

https://github.com/sandshrewmetaprotocols/metashrew
https://github.com/sandshrewmetaprotocols/metashrew-as
https://www.assemblyscript.org/introduction.html
Page cover image