Near smart contracts

From internet-court/internet-court-skill · View interactive version

Near smart contracts is an AI agent skill from the GitHub repository internet-court/internet-court-skill. 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.

How to use this skill

Skill file

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:

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:

DO NOT:

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)

2. Contract Structure (HIGH)

3. State Management (HIGH)

4. Cross-Contract Calls (MEDIUM-HIGH)

5. Contract Upgrades & Migration (MEDIUM-HIGH)

6. Chain Signatures (MEDIUM-HIGH)

7. Gas Optimization (MEDIUM)

8. Yield & Resume (MEDIUM)

9. Testing (MEDIUM)

10. Best Practices (MEDIUM)

How to Use

Read individual rule files for detailed explanations and code examples:

rules/security-storage-checks.md
rules/structure-near-bindgen.md
rules/state-collections.md
rules/xcc-promise-chaining.md
rules/upgrade-migration.md
rules/chain-signatures.md
rules/yield-resume.md
rules/best-contract-tools.md
rules/testing-integration-tests.md

Each rule file contains:

Latest Tools & Versions

Development Tools

SDK Versions

Key Features

Resources

Storage Costs Reference

| Storage | Cost | Notes |

|---------|------|-------|

| 1 byte | 0.00001 NEAR | ~10kb per 0.1 NEAR |

| 100 KB | ~1 NEAR | Approximate reference |

| AccountId | 64+ bytes | Can save 40% with base32 encoding |

| Contract code | Variable | Paid by contract account |

SDK Collections Reference

| Collection | Iterable | Clear | Ordered | Range | Use Case |

|------------|----------|-------|---------|-------|----------|

| Vector | Yes | Yes | Yes | Yes | Ordered list with index access |

| LookupMap | No | No | No | No | Fast key-value, no iteration needed |

| LookupSet | No | No | No | No | Fast membership checks |

| IterableMap | Yes | Yes | Yes | No | Key-value with iteration |

| IterableSet | Yes | Yes | Yes | No | Set with iteration |

| UnorderedMap | Yes | Yes | No | No | Key-value, unordered iteration |

| UnorderedSet | Yes | Yes | No | No | Set, unordered iteration |

| TreeMap | Yes | Yes | Yes | Yes | Sorted key-value with range queries |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.