Sui RPC - Hướng dẫn nhanh | ERPC
Hướng dẫn nhanh Sui RPC
Hướng dẫn này đưa bạn từ con số không đến một transport Sui gRPC-web đã được cấu hình với ERPC.
1. Lấy API Key của bạn
Bạn có thể lấy và kiểm tra API key trên ERPC Web Dashboard: ERPC Web Dashboard
Đã dùng ERPC cho Solana, Ethereum hoặc Avalanche? Bạn có thể dùng cùng một RPC key.
2. Cấu hình gRPC-web Transport
Sui được phục vụ qua gRPC-web dạng binary (
application/grpc-web+proto), mỗi HTTP request mang một lệnh gọi unary. Cấu hình GrpcWebFetchTransport với base URL của ERPC và API key của bạn dưới dạng Bearer token:typescript
import { GrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport'
const transport = new GrpcWebFetchTransport({
baseUrl: 'https://sui.erpc.global', // or https://edge.erpc.global/sui
format: 'binary',
meta: { Authorization: 'Bearer <YOUR_API_KEY>' },
})import { GrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport'
const transport = new GrpcWebFetchTransport({
baseUrl: 'https://sui.erpc.global', // or https://edge.erpc.global/sui
format: 'binary',
meta: { Authorization: 'Bearer <YOUR_API_KEY>' },
})Truyền transport này cho client dịch vụ unary được tạo cho Sui gRPC API. Client sẽ nối thêm
/sui.rpc.v2.<Service>/<Method> vào baseUrl, ví dụ /sui.rpc.v2.LedgerService/GetServiceInfo. Vì SDK nối path vào base URL, API key được đặt trong header Authorization thay vì tham số query api-key.Chỉ hỗ trợ lệnh gọi unary qua gRPC-web dạng binary. Không hỗ trợ request JSON-RPC, gRPC native, gRPC-web dạng text và streaming.
Bước tiếp theo
- Endpoint, đo lường mức sử dụng, và mã trạng thái: Tài liệu Sui RPC Endpoint
- Tài liệu Sui chính thức: https://docs.sui.io/references/sui-api






