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 @@ -36,6 +36,7 @@ Athena Consulting has been awarded a grant by [Atom Accelerator DAO](https://www
- [TimeLock Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/timelock)
- [Crowdfunding Contract](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/crowdfunding)
- [Token Vault](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/token-vault)
- [Profile Card](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/profile-card)

### :three: Complex Applications
- [Constant Product AMM](https://github.com/athena-consulting/cosmwasm-by-example/tree/main/constant-product-amm)
Expand Down
44 changes: 44 additions & 0 deletions profile-card/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "profile-card"
version = "0.1.0"
authors = ["gachouchani1999 <gachouchani@ndu.edu.lb>"]
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 = { version = "1.0.31" }
59 changes: 59 additions & 0 deletions profile-card/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Profile Card

This contract stores a small public profile for each wallet address. It is a
simple example of owner-controlled state: every sender can create, update, query,
list, or clear only their own profile card.

The example demonstrates:

- validating execute message fields before saving state
- using `Map` to store one record per address
- removing state with `Map::remove`
- paginating query results with `start_after` and `limit`

## Instantiate

The contract does not need any setup data.

```rust
pub struct InstantiateMsg {}
```

## Execute Messages

`SetProfile` saves a profile for the message sender. Empty optional fields are
stored as `None`, and the display name must not be empty.

```rust
SetProfile {
display_name: "Alice".to_string(),
bio: Some("CosmWasm builder".to_string()),
website: Some("https://example.com".to_string()),
}
```

`ClearProfile` removes the sender's profile.

```rust
ClearProfile {}
```

## Query Messages

`GetProfile` returns a single profile by address.

```rust
GetProfile {
address: "alice".to_string(),
}
```

`ListProfiles` returns stored profiles in address order. The query accepts an
optional `start_after` cursor and a bounded `limit`.

```rust
ListProfiles {
start_after: None,
limit: Some(10),
}
```
10 changes: 10 additions & 0 deletions profile-card/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::write_api;
use profile_card::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
Loading