Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Athena Consulting has been awarded a grant by [Atom Accelerator DAO](https://www
- [Reading and Writing From State](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/read-write-state)
- [Response and Attributes](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/responses-attributes)
- [Cosmwasm Math Examples](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/cosmwasm-math)
- [Address Book](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/address-book)
- [Cross-Contract Instantiation](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/cross-contract-instatiation)
- [Receiving CW20 Tokens](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/receiving-cw20-tokens)

Expand Down
3 changes: 3 additions & 0 deletions address-book/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
44 changes: 44 additions & 0 deletions address-book/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "address-book"
version = "0.1.0"
authors = ["alexgduarte"]
edition = "2021"

exclude = [
"contract.wasm",
"hash.txt",
]

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
opt-level = 3
debug = false
rpath = false
lto = true
debug-assertions = false
codegen-units = 1
panic = 'abort'
incremental = false
overflow-checks = true

[features]
backtraces = ["cosmwasm-std/backtraces"]
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache,target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.10
"""

[dependencies]
cosmwasm-schema = "1.1.3"
cosmwasm-std = "1.1.3"
cw-storage-plus = "1.0.1"
cw2 = "1.0.1"
schemars = "0.8.10"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = "1.0.31"
72 changes: 72 additions & 0 deletions address-book/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Address Book

This example shows how a CosmWasm contract can keep a small address book in
contract storage.

The contract owner can:

- Add a named contact with a validated blockchain address.
- Remove a contact by name.
- Transfer ownership to another address.

Anyone can query:

- The current owner.
- One contact by name.
- A paginated list of contacts.

The example is intentionally simple. It focuses on common building blocks that
new CosmWasm developers reuse often: `Item` configuration, `Map` storage,
address validation, owner-only execute messages, and paginated range queries.

## Messages

Instantiate with an optional owner. If no owner is provided, the sender becomes
the owner.

```json
{}
```

Add a contact:

```json
{
"add_contact": {
"name": "validator-one",
"address": "cosmos1...",
"note": "Primary validator address"
}
}
```

Remove a contact:

```json
{
"remove_contact": {
"name": "validator-one"
}
}
```

Query one contact:

```json
{
"contact": {
"name": "validator-one"
}
}
```

List contacts with optional pagination:

```json
{
"contacts": {
"start_after": "validator-one",
"limit": 10
}
}
```
Loading