near-smart-contracts
24
总安装量
11
周安装量
#15309
全站排名
安装命令
npx skills add https://github.com/near/agent-skills --skill near-smart-contracts
Agent 安装分布
opencode
8
github-copilot
8
gemini-cli
8
codex
7
amp
5
kimi-cli
5
Skill 文档
NEAR Smart Contracts Development
Comprehensive guide for developing secure and efficient smart contracts on NEAR Protocol using Rust and the NEAR SDK.
When to Apply
Reference these guidelines when:
- Writing new NEAR smart contracts in Rust
- Reviewing existing contract code for security and optimization
- Implementing cross-contract calls and callbacks
- Managing contract state and storage
- Testing and deploying NEAR contracts
- Optimizing gas usage and performance
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Security & Safety | CRITICAL | security- |
| 2 | Contract Structure | HIGH | structure- |
| 3 | State Management | HIGH | state- |
| 4 | Cross-Contract Calls | MEDIUM-HIGH | xcc- |
| 5 | Gas Optimization | MEDIUM | gas- |
| 6 | Testing | MEDIUM | testing- |
| 7 | Best Practices | MEDIUM | best- |
Quick Reference
1. Security & Safety (CRITICAL)
security-storage-checks– Always validate storage operationssecurity-access-control– Implement proper access control for sensitive functionssecurity-reentrancy– Protect against reentrancy attackssecurity-overflow– Use checked arithmetic to prevent overflowsecurity-callback-validation– Validate callback results and handle failuressecurity-private-callbacks– Mark callbacks as privatesecurity-yoctonear-validation– Validate attached deposits
2. Contract Structure (HIGH)
structure-near-bindgen– Use #[near_bindgen] macro for contract structstructure-initialization– Implement proper initialization patternsstructure-versioning– Plan for contract upgrades with versioningstructure-events– Emit events for important state changesstructure-standards– Follow NEAR Enhancement Proposals (NEPs)
3. State Management (HIGH)
state-collections– Use NEAR SDK collections (Vector, LookupMap, UnorderedMap, etc.)state-serialization– Use efficient serialization (Borsh)state-lazy-loading– Load state lazily to save gasstate-pagination– Implement pagination for large datasetsstate-migration– Plan state migration strategies
4. Cross-Contract Calls (MEDIUM-HIGH)
xcc-promise-chaining– Chain promises correctlyxcc-callback-handling– Handle all callback scenarios (success, failure)xcc-gas-management– Allocate appropriate gas for cross-contract callsxcc-error-handling– Implement robust error handlingxcc-result-unwrap– Never unwrap promise results without checks
5. Gas Optimization (MEDIUM)
gas-batch-operations– Batch operations to reduce transaction costsgas-minimal-state-reads– Minimize state reads and writesgas-efficient-collections– Choose appropriate collection typesgas-view-functions– Mark read-only functions as viewgas-avoid-cloning– Avoid unnecessary cloning of large data
6. Testing (MEDIUM)
testing-unit-tests– Write comprehensive unit teststesting-integration-tests– Use workspaces-rs for integration teststesting-simulation-tests– Test with near-sdk-sim or workspacestesting-edge-cases– Test boundary conditions and edge casestesting-gas-profiling– Profile gas usage in tests
7. Best Practices (MEDIUM)
best-panic-messages– Provide clear panic messagesbest-logging– Use env::log_str for debuggingbest-documentation– Document public methods and complex logicbest-error-types– Define custom error typesbest-constants– Use constants for magic numbers
How to Use
Read individual rule files for detailed explanations and code examples:
rules/security-storage-checks.md
rules/structure-near-bindgen.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and NEAR-specific considerations
Resources
- NEAR Documentation: https://docs.near.org
- NEAR SDK Rust: https://docs.near.org/sdk/rust/introduction
- NEAR Examples: https://github.com/near-examples
- NEAR Standards (NEPs): https://github.com/near/NEPs
- Security Best Practices: https://docs.near.org/develop/contracts/security/welcome
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md