Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)7.0k · #13656

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.md

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/internet-court/internet-court-skill/blob/main/vendored/near/near-smart-contracts/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

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 new to 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.toml with proper dependencies and build settings
  • Creates proper project structure with src/lib.rs template
  • 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 deposits
  • security-access-control - Implement proper access control using predecessor_account_id
  • security-reentrancy - Protect against reentrancy attacks (update state before external calls)
  • security-overflow - Use overflow-checks = true in Cargo.toml to prevent overflow
  • security-callback-validation - Validate callback results and handle failures
  • security-private-callbacks - Mark callbacks as #[private] to prevent external calls
  • security-yoctonear-validation - Validate attached deposits with #[payable] functions
  • security-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] patterns
  • structure-versioning - Plan for contract upgrades with versioning mechanisms
  • structure-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.

repo: internet-court/internet-court-skill

Độ 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

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự