Aller au contenu
Skillpedia
API et serveurs (backend)7.0k · #13656

near-smart-contracts

Ce qu’il fait

Ce skill guide l'écriture et la relecture de contrats intelligents pour la blockchain NEAR en Rust. Il s'adresse aux développeurs qui construisent sur NEAR et veulent un code de contrat sûr et efficace.

Quand l’utiliser

  • ✓Quand vous commencez un nouveau contrat intelligent NEAR en Rust.
  • ✓Quand vous voulez qu'un contrat NEAR existant soit relu pour la sécurité et la consommation de gaz.
  • ✓Quand votre contrat a besoin d'appels entre contrats, de rappels ou de gestion du stockage.

Lien du skill

https://github.com/internet-court/internet-court-skill/blob/main/vendored/near/near-smart-contracts/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/internet-court/internet-court-skill/blob/main/vendored/near/near-smart-contracts/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Peux-tu m'aider à écrire un contrat intelligent NEAR en Rust qui stocke une liste de votes d'utilisateurs ?”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

L'agent crée le projet avec l'outil cargo-near, puis écrit le code du contrat avec les bonnes règles d'état et d'accès. Il relit les appels entre contrats et l'usage du stockage, et explique comment tester et déployer.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

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::
Questions fréquentes

Comment le skill démarre-t-il un nouveau projet ?

Le skill demande d'utiliser la commande cargo near new plutôt que de créer les fichiers du projet à la main.

Quelle version du SDK suit-il ?

Il se base sur near-sdk version 5, avec la syntaxe de macros actuelle.

Couvre-t-il les tests et le déploiement ?

Oui. Il couvre les tests, le déploiement et les moyens de réduire la consommation de gaz.

Détails

Description originale de l’auteur

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

Popularité

Étoiles GitHub
7.0k
Position au classement
#13656
Licence
—
Mis à jour
26/10/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires