Skip to content

Commit

Permalink
feat(cosmwasm): populate contract related readme files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Afanasyev committed Apr 17, 2024
1 parent b61a0dc commit 04b4e5b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
82 changes: 81 additions & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
# Warden Contracts

This repo contains bindings (with usage examples) for accessing functionality of Warden Protocol blockchain
This repo contains bindings (with usage examples) for accessing core functionality of Warden Protocol blockchain
from CosmWasm contracts.

## Prerequisites

- You need rust to generate schema files.
- You need a Docker to build a contract.
- You need an account in the Warden Protocol blockchain with some balance in order to deploy contracts and perform transactions on it.

## Generate Schema

To generate schema files perform following commands:

```shell
# generate bindings schema
cd packages/bindings
cargo build
cargo run schema

cd ../..

# generate sapmle contract schema
cd contracts
cargo build
cargo run schema
```

## Build

```shell
Expand All @@ -11,3 +35,59 @@ docker run --rm -v "$(pwd)":/code \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.13.0
```

After a successful build you'll see a newly generated `sample.wasm` file in the `artifacts` directory.

## Deploy a Contract

We assume that your have a `wardend` executable's directory in your `$PATH` environment variable in order to perform following steps.
Also, your account should be added to the `wardend`'s keychain. Following commands use `alice` name for such account.

```shell
wardend tx wasm store artifacts/sample.wasm --from alice -y -b sync --chain-id warden --gas 2000000
```

Now you should find an id that system assigned to your code.
One of the methods to do this is simply list all stored code bundles and find the last one.

```shell
wardend query wasm list-code
```

Let's assume it's 100. Next step is to instantiate our contract using previously deployed code:

```shell
wardend tx wasm instantiate 100 '{}' --from alice --label "Group 1" --no-admin -y --chain-id warden
```

Let's find out address of the newly created contract. The simple way to do it is to query all contracts
with code id that we used previously, and find the last one:

```shell
wardend query wasm list-contract-by-code 100
```

Let's assume it's address is `warden1ghd753shjuwexxywmgs4xz7x2q732vcnkm6h2pyv9s6ah3hylvrqtn83hn`
and store it to the `$contract` environment variable for the convenience:

```shell
contract=warden1ghd753shjuwexxywmgs4xz7x2q732vcnkm6h2pyv9s6ah3hylvrqtn83hn
```

Now we are ready to interact with our contract!

# Interacting with Contract

You can query it's state, for example, let's list all existing keys:

```shell
wardend query wasm contract-state smart $contract '{ "warden_all_keys": {"pagination":{"limit":0,"reverse":false}, "derive_wallets":[]} }'--chain-id warden
```

And perform transactions, let's create request for a new key:

```shell
wardend tx wasm execute $contract '{ "new_key_request": { "space_id": 1, "keychain_id": 2, "key_type": 1, "btl": 888, "intent_id": 0 } }' --from alice -y --chain-id warden
```

Note that `space_id` 1 and `keychain_id` 2 should already exist before your transaction.
7 changes: 7 additions & 0 deletions contracts/contracts/sample/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Sample

This is a sample contract which uses bindings for the core Warden Protocol blockchain functionality.

You can deploy it by itself, or you can use it as a starting point for your own contract.

Not that this is a preview, so only limited functionality available right now.
The sample contract exposes `NewKeyRequest` transaction and `AllKeys` query, but more on the way!
8 changes: 8 additions & 0 deletions contracts/packages/bindings/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Bindings

This crate provides bindings for the Warden Protocol blockchain core functionality.
You can use it in your own contracts to interact with a Warden Protocol.

Not that this is a preview, so only limited functionality available right now.
You can execute `NewKeyRequest` and query `AllKeys`, but more on the way!

To start using Warden Protocol from the CosmWasm contracts, please refer to sample contract.

0 comments on commit 04b4e5b

Please sign in to comment.