CosmWasm AO is a CosmWasm-based smartcontract network on AO.
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 | |
cwao-units | Running AO compatible Units (MU / SU / CU) | |
cwao-tools | Contract Testing Tools |
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.
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.
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
- Arweave Testnet (ArLocal) : http://localhost:1984
- Messenger Unit (MU) : http://localhost:1985
- Scheduler Unit (SU) : http://localhost:1986
- Compute Unit (CU) : http://localhost:1987
cd cosmwasm-ao/dapps/cw20
yarn
yarn dev
Now a demo dapp is running at localhost:3000.
Follow this tutorial to write some CosmWasm contracts.
And compile it with the following command.
cargo build --target wasm32-unknown-unknown --release
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
.
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.
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.
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
.
yarn add cwao
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