near-smart-contracts
Skill này làm gì
Skill này hướng dẫn viết và rà soát hợp đồng thông minh cho blockchain NEAR bằng Rust. Skill dành cho lập trình viên xây trên NEAR và muốn mã hợp đồng an toàn, hiệu quả.
Khi nào nên dùng
- ✓Khi bạn bắt đầu một hợp đồng thông minh NEAR mới bằng Rust.
- ✓Khi bạn muốn rà soát một hợp đồng NEAR có sẵn về bảo mật và mức dùng gas.
- ✓Khi hợp đồng cần gọi chéo giữa các hợp đồng, callback hoặc xử lý lưu trữ.
Liên kết skill
https://github.com/internet-court/internet-court-skill/blob/main/vendored/near/near-smart-contracts/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể giúp tôi viết một hợp đồng thông minh NEAR bằng Rust để lưu danh sách bình chọn của người dùng không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tạo dự án bằng công cụ cargo-near, rồi viết mã hợp đồng với quy tắc trạng thái và quyền truy cập phù hợp. Agent rà soát các lệnh gọi giữa hợp đồng và cách dùng bộ nhớ, rồi giải thích cách kiểm thử và triển khai.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
NEAR Smart Contracts Development
Comprehensive guide for developing secure and efficient smart contracts on NEAR Protocol using Rust and the NEAR SDK (v5.x).
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
Getting Started
Prerequisites
Install the required tools before starting development:
# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Add wasm32 target for compiling contracts
rustup target add wasm32-unknown-unknown
# Install cargo-near (build, deploy, and manage contracts)
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh
# Install near-cli-rs (interact with NEAR network)
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/near-cli-rs/releases/latest/download/near-cli-rs-installer.sh | sh
Create a New Project
CRITICAL: ALWAYS run
cargo near newto create new projects. NEVER manually create Cargo.toml, lib.rs, or any project files. The command generates all required files with correct configurations.
# REQUIRED: Create a new contract project using the official template
cargo near new my-contract
# Navigate to project directory
cd my-contract
# Build the contract
cargo near build
# Run tests
cargo test
Why cargo near new is mandatory:
- Generates correct
Cargo.tomlwith proper dependencies and build settings - Creates proper project structure with
src/lib.rstemplate - Includes integration test setup in
tests/directory - Configures release profile with
overflow-checks = true - Sets up correct crate-type for WASM compilation
- Avoids common configuration mistakes that cause build failures
DO NOT:
- Manually create
Cargo.toml - Manually create
src/lib.rs - Copy-paste project structure from examples
- Skip this step and create files directly
Project Structure
my-contract/
├── Cargo.toml # Dependencies and project config
├── src/
│ └── lib.rs # Main contract code
├── tests/ # Integration tests
│ └── test_basics.rs
└── README.md
Deploy to Testnet
# Create a testnet account (if needed)
near account create-account sponsor-by-faucet-service my-contract.testnet autogenerate-new-keypair save-to-keychain network-config testnet create
# Build in release mode
cargo near build --release
# Deploy to testnet
cargo near deploy my-contract.testnet without-init-call network-config testnet sign-with-keychain send
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 | Contract Upgrades | MEDIUM-HIGH | upgrade- |
| 6 | Chain Signatures | MEDIUM-HIGH | chain- |
| 7 | Gas Optimization | MEDIUM | gas- |
| 8 | Yield & Resume | MEDIUM | yield- |
| 9 | Testing | MEDIUM | testing- |
| 10 | Best Practices | MEDIUM | best- |
1. Security & Safety (CRITICAL)
security-storage-checks- Always validate storage operations and check depositssecurity-access-control- Implement proper access control usingpredecessor_account_idsecurity-reentrancy- Protect against reentrancy attacks (update state before external calls)security-overflow- Useoverflow-checks = truein Cargo.toml to prevent overflowsecurity-callback-validation- Validate callback results and handle failuressecurity-private-callbacks- Mark callbacks as#[private]to prevent external callssecurity-yoctonear-validation- Validate attached deposits with#[payable]functionssecurity-sybil-resistance- Implement minimum deposit checks to prevent spam
2. Contract Structure (HIGH)
structure-near-bindgen- Use#[near(contract_state)]macro for contract struct (replaces old#[near_bindgen])structure-initialization- Implement proper initialization with#[init]patternsstructure-versioning- Plan for contract upgrades with versioning mechanismsstructure-events- Use `env::
Câu hỏi thường gặp
Skill bắt đầu dự án mới như thế nào?
Skill khuyên dùng lệnh cargo near new thay vì tự tạo các tệp dự án bằng tay.
Skill theo phiên bản SDK nào?
Skill dựa trên near-sdk phiên bản 5 với cú pháp macro hiện tại.
Skill có bao quát kiểm thử và triển khai không?
Có. Skill bao quát kiểm thử, triển khai và cách giảm mức dùng gas.
Chi tiết
Mô tả gốc của tác giả
NEAR Protocol smart contract development in Rust. Use when writing, reviewing, or deploying NEAR smart contracts. Covers contract structure, state management, cross-contract calls, testing, security, and optimization patterns. Based on near-sdk v5.x with modern macro syntax.
Độ phổ biến
- Sao GitHub
- 7.0k
- Vị trí xếp hạng
- #13656
- Giấy phép
- —
- Cập nhật
- 26/10/2026
Bình luận
- …
Thêm skill từ kho mã này
internet-court
7.0kGiúp agent của bạn thanh toán, thuê hoặc giao dịch an toàn với một agent AI khác hoặc dịch vụ trả phí, và chỉ đến hướng dẫn chuyên sâu phù hợp.
genlayer-erc7710-connector
7.0kGiúp agent của bạn kết nối kết quả đánh giá AI với hệ thống quyền hạn, để một đánh giá xấu có thể hạn chế hoặc hủy quyền của agent.
genlayer-intelligent-contracts
7.0kGiúp agent của bạn xác định quy tắc, bằng chứng và đầu ra của một AI judge kiểm tra xem agent khác có làm đúng nhiệm vụ được ủy quyền hay không.
x402-erc7710
7.0kGiúp agent của bạn trả tiền cho dịch vụ web theo từng yêu cầu, và thiết lập chi tiêu định kỳ nằm trong ngân sách quyền hạn.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.