npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cwao

v0.5.5

Published

CWAO SDK makes CosmWasm AO development a breeze.

Downloads

71

Readme

CWAO SDK

CWAO SDK makes CosmWasm AO development a breeze.

Especially,

  • working with ANS-104 data and tags
  • interacting with AO units (MU, SU, CU, and Arweave Storage)
  • executing CosmWasm functions via AO

Install

yarn add cwao

API Reference

CWAO

const { CWAO } = require("cwao")
const cwao = new CWAO({ protocol, variant, mu, su, cu, wallet, arweave })

deploy

Upload contract wasm code to Arweave.

const wasm = require("fs").readFileSync(MODULE_BINARY_FILE_PATH)
const module_id = await cwao.deploy(wasm)

setSU

Set a scheduler unit URL for contract processes.
The scheduler address will be the wallet address set to the CWAO instance.

await cwao.setSU({ url, ttl, tags })

instantiate

Instantiate a contract process.

const process_id = await cwao.instantiate({ module, scheduler, input })

execute

Execute a CosmWasm function.

await cwao.execute({ process, action, input })

query

Query a CosmWasm function. This will send out a read-only message.

await cwao.query({ process, action, input })

cw

CW provides a simpler interface for a CosmWasm contract by presetting the process_id.

const cw = await cwao.cw({ module, scheduler })
await cw.i(input) // instanciate, this will assign the resulting process_id
await cw.e(action, input) // execute
await cw.q(action, input) // query

If the contract/process is already instantiated, you can pass the process_id.

const cw = await cwao.cw({ process })
await cw.e(action, input)
await cw.q(action, input)

MU

To interact with a messenger unit, you could use it as a standalone MU instance or as part of CWAO.

const { MU } = require("cwao")
const mu = new MU({ url })

get : /

const text = await cwao.mu.get()

post : /

const { id } = await cwao.mu.post(dataitem)

SU

To interact with a sucheduler unit, you could use it as a standalone SU instance or as part of CWAO.

const { SU } = require("cwao")
const su = new SU({ url })

get : [GET] /

const json = await cwao.su.get()

timestamp : [GET] /timestamp

const json = await cwao.su.timestamp()

process : [GET] /{process-id}

const json = await cwao.su.process(process_id)

processes : [GET] /processes/{process-id}

const json = await cwao.su.processes(process_id)

post : [POST] /

const { id, timestamp } = await cwao.su.post(dataitem)

CU

To interact with a compute unit, you could use it as a standalone CU instance or as part of CWAO.

const { CU } = require("cwao")
const cu = new CU({ url })

get : [GET] /

const json = await cwao.cu.get()

state : [GET] /state/{process-id}

const arrayBuffer = await cwao.cu.state(process_id)

result : [GET] /result/{message-id}?process-id={process-id}

const json = await cwao.cu.result(message_id, process_id)

Data

To work with ANS-104 data objects, you could use it as a standalone Data instance or as part of CWAO.

const { Data } = require("cwao")
const data = new Data({ protocol, variant, wallet, arweave })

dataitem

Construct a signed DataItem.

const dataitem = await cwao.data.dataitem({ fields, data, signer })

bundle

Construct a signed Bundle.

const dataitems = [ dataitem_1, dataitem_2, dataitem_3, ... ]
const bundle = await cwao.data.bundle({ dataitems, signer })

tx

Construct a signed transaction.

const tx = await cwao.data.tx({ bundle })

post

Post a transaction to Arweave.

const result = await cwao.data.post({ tx })

send

An omni-send function. you can pass any of the previous data objects and it just works.

const json = await cwao.data.send({ fields, data, dataitems, bundle, tx, signer })

nest

To next bundles, it adds the necessary tags to a Bundle.

const nestable = cwao.data.nest(bundle)
const dataitem = await cwao.data.dataitem({ fields, data: nestable, signer })

verifyItem

Validate AO compatibility of a DataItem in binary format.

const { item, valid , type } = await cwao.data.verifyItem(binary)

Tag

To work with AO compatible tags, you could use it as a standalone Tag instance or as part of Data.

const { Tag } = require("cwao")
const tag = new Tag({ protocol, variant })

module

Constract a tag for Module message.

const tags = cwao.data.tag.module(
  { input_encoding, output_encoding, module_format },
  custom
)

scheduler

Constract a tag for Scheduler-Location message.

const tags = cwao.data.tag.scheduler({ url, ttl }, custom )

process

Constract a tag for Process message.

const tags = cwao.data.tag.process({ module, scheduler }, custom )

message

Constract a normal Message message.

const tags = cwao.data.tag.message({ action, input, read_only }, custom )

assignment

Constract an Assignement message.

const tags = cwao.data.tag.assignment(
  { epoch, nonce, hash, height, process, timestamp }, 
  custom
)

validate

Validate tags.

const { type, valid } = cwao.data.tag.validate(dataitem)

GQL

Get Arweave data from a GraphQL endpoint.

const { GQL } = require("cwao")
const gql = new GQL({ url })

getTx

const node_query = `{ id owner { address } tags { name value } }`
const tx = await gql.getTx(id, node_query)

getSU

To get a SU URL, either path scheduler_address or process_id.

const { url, ttl } = await gql.getSU({ address, process })

getMessages

To get messages sent to a process.

const { tx, cursor, error } = await gql.getMessages(process_id)

getMessagesByIds

To get messages by transaction ids.

const { tx, cursor, error } = await gql.getMessagesByIds(ids)

getAll

By default, gql functions return only the first 1000 items. getAll iterates with a cursor and returns all items.

const { tx, cursor, error } = await gql.getAll(func, args)

// example with getMessages
const { tx, cursor, error } = await gql.getAll("getMessages", [process_id])

// example with getMessagesByIds
const { tx, cursor, error } = await gql.getAll("getMessagesByIds", [ids])