Skill站外收录 @skilllib/skill-2014279423569113090
cosmwasm-contract
面向 Axone 协议的 CosmWasm 合约开发支持,涵盖从初始化、执行、查询到迁移的全生命周期实现,基于 Abstract SDK 提供标准化合约结构、状态管理、错误处理及模块化处理器设计,适用于构建可组合、可升级的链上智能合约。
区块链 AI 技能
Skills.MD
# CosmWasm Smart Contract Development with Abstract SDK
This skill helps you develop CosmWasm smart contracts for the Axone protocol using the Abstract SDK framework.
## When to use this skill
Use this skill when you need to:
- Create a new smart contract from scratch
- Implement contract handlers (instantiate, execute, query, migrate)
- Define contract state and storage
- Work with the Abstract `AppContract` pattern
- Define error types for contracts
## Contract Structure
Every contract follows this standard structure:
```text
contracts/<contract-name>/
├── Cargo.toml # Dependencies and features
├── Makefile.toml # Contract-specific tasks
├── README.md # Contract documentation
├── metadata.json # Abstract module metadata
├── schema/ # Generated JSON schemas
├── src/
│ ├── lib.rs # Public exports and constants
│ ├── contract.rs # AppContract type and entry points
│ ├── msg.rs # Message types (Instantiate, Execute, Query, Migrate)
│ ├── state.rs # State storage definitions
│ ├── error.rs # Error types
│ ├── handlers/ # Handler implementations
│ │ ├── mod.rs
│ │ ├── instantiate.rs
│ │ ├── execute.rs
│ │ ├── query.rs
│ │ └── migrate.rs
│ ├── replies/ # Reply handlers (optional)
│ └── bin/ # Binary scripts (schema, publish, install)
└── tests/
└── integration.rs # Integration tests
```
## Key Patterns
### 1. Module ID and Namespace (lib.rs)
```rust
pub const AXONE_NAMESPACE: &str = "axone";
pub const CONTRACT_NAME: &str = "my-contract";
pub const CONTRACT_ID: &str = const_format::concatcp!(AXONE_NAMESPACE, ":", CONTRACT_NAME);
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
```
### 2. AppContract Definition (contract.rs)
```rust
use abstract_app::AppContract;
pub type MyContract = AppContract<
MyContractError,
MyContractInstantiateMsg,
MyContractExecuteMsg,
MyContractQueryMsg,
MyContractMigrateMsg,
>;
const APP: MyContract = MyContract::new(CONTRACT_ID, APP_VERSION, None)
.with_instantiate(handlers::instantiate_handler)
.with_execute(handlers::execute_handler)
.with_query(handlers::query_handler)
.with_migrate(handlers::migrate_handler)
.with_dependencies(&[]);
#[cfg(feature = "export")]
abstract_app::export_endpoints!(APP, MyContract);
abstract_app::cw_orch_interface!(APP, MyContract, MyContractInterface);
```
### 3. Handler Functions
```rust
// handlers/execute.rs
use crate::contract::{MyContract, MyContractResult};
use crate::msg::MyContractExecuteMsg;
use abstract_app::traits::AbstractNameService;
pub fn execute_handler(
deps: DepsMut,
env: Env,
info: MessageInfo,
app: MyContract,
msg: MyContractExecuteMsg,
) -> MyContractResult {
match msg {
MyContractExecuteMsg::DoSomething { param } => do_something(deps, env, info, app, param),
}
}
```
### 4. State Management (state.rs)
```rust
use cw_storage_plus::{Item, Map};
pub const CONFIG: Item<Config> = Item::new("config");
pub const ITEMS: Map<&str, ItemData> = Map::new("items");
```
### 5. Error Types (error.rs)
```rust
use thiserror::Error;
#[derive(Debug, Error, PartialEq)]
pub enum MyContractError {
#[error("{0}")]
Std(#[from] StdError),
#[error("{0}")]
Abstract(#[from] AbstractError),
#[error("{0}")]
AbstractSdk(#[from] AbstractSdkError),
#[error("{0}")]
DappError(#[from] AppError),
// Custom errors
#[error("Unauthorized")]
Unauthorized {},
}
```
## Building and Testing
```bash
# Build the contract
cargo make build
# Build WASM
cargo make wasm
# Run tests
cargo make test-unit
# Generate schemas
cargo make schema
```
## Best Practices
1. **Use Abstract SDK features** - Leverage `AbstractNameService`, `Bank`, and other SDK modules
2. **Keep handlers focused** - Each handler function should do one thing well
3. **Document all messages** - Every message variant needs doc comments for schema generation
4. **Derive traits consistently** - Use `cw_serde`, `ExecuteFns`, `QueryFns`
5. **Test error cases** - Cover both success and failure paths in tests
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「cosmwasm-contract」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次