Skip to content

weavedb/cosmwasm-ao

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CosmWasm AO

CosmWasm AO is a CosmWasm-based smartcontract network on AO.

Packages

CosmWasm AO Development is in a very early state. Everything is subject to changes.

We will launch a public testnet on AO in the coming months.

Package Usage
cwao CosmWasm AO SDK npm version
cwao-units Running AO compatible Units (MU / SU / CU) npm version
cwao-tools Contract Testing Tools npm version

AO

AO is a hyper parallel computation protocol on top of Arweave. It runs any number of Wasm-based smart contract processes in parallel with actor model messaging mechanism.

Actor Model

CosmWasm is actor model smart contract initially built for, but not limited to, CosmosSDK blockchains. Actor model is the only viable way to hyper scale computation in decentralized networks and AO and CosmWasm turned out to be a perfect duo.

Set up Local Nodes

To test it out, ArLocal and 3 AO units (MU, CU, SU) need to be running locally.

git clone https://github.com/weavedb/cosmwasm-ao.git
cd cosmwasm-ao/ao
yarn
yarn start

CW20 Token Demo

cd cosmwasm-ao/dapps/cw20
yarn
yarn dev

Now a demo dapp is running at localhost:3000.

Write CosmWasm Contract

Follow this tutorial to write some CosmWasm contracts.

And compile it with the following command.

cargo build --target wasm32-unknown-unknown --release

Sample Contract

cd cosmwasm-ao/cosmwasm/cw20
cargo build --target wasm32-unknown-unknown --release

The binary file to deploy will be at target/wasm32-unknown-unknown/release/contract.wasm.

Differences from Original CosmWasm

CosmWasm on AO has a couple of pivotal differences from the original CosmWasm on CosmosSDK. This is to be compatible with the AO specification, which brings out the full advantage of the actor model for hyperparallelism and scalability.

No Atomic add_message Failures

In the original CosmWasm, you can call cross contract functions with add_message and atomically fail if the target contract execution fails. But this is not the case with AO since AO is pure actor model. Use add_submessage instead to achieve 2 way communications between processes.

IBC on AO is also under development, which will enable cross-chain communications between AO processes and other blockchains.

No Querier to Read Other Contracts

For the same reason, Querier to read states from other contracts are disabled in CosmWasm on AO. This behaviour requires inefficient and blocking synchronous operations between multiple processes, and would be the biggest bottleneck to the hyperparallelism and hyper scalability of the AO network. We believe almost all the logic with Querier can be replaced with asynchronous messaging between processes using add_submessage and IBC.

CosmWasm AO SDK

Installing SDK

yarn add cwao

Using SDK in Node Script

const { CWAO } = require("cwao")

// wallet = Arweave wallet jwk loaded with enough $AR
const cwao = new CWAO({ wallet })

// get module binary
const module_binary = require("fs").readFileSync(module_binary_file_path)

// deploy contract (module = CosmWasm contract binary)
const module = await cwao.deploy(module_binary)

// assign scheduler unit to wallet address
await cwao.setSU({ url: "http://localhost:1986" })

// get scheduler address for the process
const scheduler = await cwao.arweave.wallets.jwkToAddress(wallet)

// instantiate contract
const process = await cwao.instantiate({ module,  scheduler, input: { num: 1 } })

// execute contract
await cwao.execute({ process: process.id, action: "Add", input: { num: 2 } })

// query contract
const { num } = await cwao.query({process: process.id, action: "Num", input: {}})


// a much simpler way 
const cw = cwao.cw({ module, scheduler }) // get CW instance
await cw.i({ num: 1 }) // instantiate
await cw.e("Add", { num: 2 }) // execute
const { num } = await cw.q("Num") // query

Testing Contracts

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published