starknet-js
Skill này làm gì
Skill này là tài liệu tham khảo cho thư viện starknet.js phiên bản 9, dùng để kết nối ứng dụng với blockchain Starknet. Nó dành cho nhà phát triển viết mã front end hoặc back end để đọc hoặc gửi giao dịch trên Starknet.
Khi nào nên dùng
- ✓Khi bạn đang xây ứng dụng Starknet để đọc dữ liệu hợp đồng hoặc gửi giao dịch.
- ✓Khi bạn cần kết nối ví hoặc thiết lập luồng paymaster trong ứng dụng Starknet.
- ✓Khi bạn cần ước tính phí hoặc xử lý giao dịch trong starknet.js.
Liên kết skill
https://github.com/internet-court/internet-court-skill/blob/main/vendored/starknet/starknet-js/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ể chỉ tôi cách đọc số dư từ một hợp đồng Starknet trong ứng dụng TypeScript bằng starknet.js không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent thiết lập một provider cho mạng Starknet, rồi tạo đối tượng hợp đồng để đọc dữ liệu hoặc đối tượng tài khoản để ký giao dịch. Nó tuân theo cách thư viện tách vai trò chỉ đọc và vai trò ký.
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.
starknet.js v9.x SDK
Related modules: skills catalog.
When to Use
- Building Starknet apps with provider, account, contract, wallet, or paymaster flows.
When NOT to Use
- Cairo contract authoring, deployment-only runbooks, or security audits.
Quick Start
npm install starknet
Minimal setup to read from Starknet:
import { RpcProvider, Contract } from 'starknet';
const provider = await RpcProvider.create({ nodeUrl: 'https://rpc.starknet.lava.build' });
const contract = new Contract(abi, contractAddress, provider);
const result = await contract.get_balance();
Core Architecture
Provider -> Account -> Contract
| | |
Network Identity Interaction
- Provider: Read-only network connection (RpcProvider)
- Account: Extends Provider with signing and transaction capabilities
- Contract: Type-safe interface to deployed contracts
Use Provider for read operations, Account for write operations.
Provider Setup
import { RpcProvider } from 'starknet';
// Recommended: Auto-detect RPC spec version
const provider = await RpcProvider.create({
nodeUrl: 'https://rpc.starknet.lava.build'
});
Networks:
- Mainnet:
https://rpc.starknet.lava.build - Sepolia:
https://rpc.starknet-testnet.lava.build
Key Methods:
const chainId = await provider.getChainId();
const block = await provider.getBlock('latest');
const nonce = await provider.getNonceForAddress(accountAddress);
await provider.waitForTransaction(txHash);
// Read storage directly
const value = await provider.getStorageAt(contractAddress, storageKey);
Account Management
Account Creation (4 Steps)
Step 1: Compute address
import { hash, ec, encode, CallData } from 'starknet';
// IMPORTANT: `stark.randomAddress()` returns an address-like random felt and is NOT a private key.
// Use a real stark curve private key generator.
const privateKey = '0x' + encode.buf2hex(ec.starkCurve.utils.randomPrivateKey());
const publicKey = ec.starkCurve.getStarkKey(privateKey);
// NOTE: account class hashes are network/account-type dependent.
// Treat this as an example only (verify the correct class hash for your setup).
const classHash = '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688'; // example
const constructorCalldata = CallData.compile({ publicKey });
const address = hash.calculateContractAddressFromHash(publicKey, classHash, constructorCalldata, 0);
Step 2: Fund the address with STRK before deployment.
Step 3: Deploy
import { Account } from 'starknet';
// NOTE: Account constructor signature varies across starknet.js versions.
// If this doesn't typecheck for your version, refer to the official docs.
const account = new Account({ provider, address, signer: privateKey, cairoVersion: '1' });
const { transaction_hash } = await account.deployAccount({
classHash,
constructorCalldata,
addressSalt: publicKey
});
await provider.waitForTransaction(transaction_hash);
Step 4: Use the account for transactions.
Connect to Existing Account
const account = new Account({
provider,
address: '0x123...',
signer: privateKey,
cairoVersion: '1' // Optional, auto-detected if omitted
});
Contract Interaction
Connect to Contract
import { Contract } from 'starknet';
const contract = new Contract(abi, contractAddress, provider); // Read-only
const writeContract = new Contract(abi, contractAddress, account); // Read-write
Typed Contract (Type-Safe)
// Get full TypeScript autocomplete and type checking from ABI
const typedContract = contract.typedv2(abi);
const balance = await typedContract.balanceOf(userAddress);
Read State
const balance = await contract.get_balance();
const userBalance = await contract.balanceOf(userAddress);
Write (Execute)
const tx = await contract.increase_balance(100);
await provider.waitForTransaction(tx.transaction_hash);
Multicall (Batch Transactions)
import { CallData, cairo } from 'starknet';
const calls = [
{
contractAddress: tokenAddress,
entrypoint: 'approve',
calldata: CallData.compile({ spender: bridgeAddress, amount: cairo.uint256(1000n) })
},
{
contractAddress: bridgeAddress,
entrypoint: 'deposit',
calldata: CallData.compile({ amount: cairo.uint256(1000
Câu hỏi thường gặp
Provider và account khác nhau thế nào?
Provider là quyền truy cập mạng chỉ đọc, còn account có thể ký và gửi giao dịch.
Skill bao gồm những mạng nào?
Skill liệt kê địa chỉ RPC của mainnet Starknet và testnet Sepolia.
Skill có bao gồm viết hợp đồng không?
Không. Viết hợp đồng và kiểm toán bảo mật nằm ngoài skill này.
Chi tiết
Mô tả gốc của tác giả
Reference for building Starknet applications using starknet.js v9.x SDK, including contract interaction, account management, transaction handling, fee estimation, wallet integration, and paymaster flows.
Độ phổ biến
- Sao GitHub
- 7.0k
- Vị trí xếp hạng
- #13687
- 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ủ.