Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Rust gRPC API

A thin gRPC server that wraps the Sui JSON-RPC API, demonstrating how a production backend interacts with on-chain Move contracts.

Architecture

┌────────────┐        ┌──────────────────┐        ┌──────────────────┐
│  gRPC      │  proto │  move-course-api │  HTTP  │  Sui Full Node   │
│  Client    │───────▶│  (tonic server)  │───────▶│  JSON-RPC        │
└────────────┘        └──────────────────┘        └──────────────────┘
  • Protocol Buffers define a typed contract between client and server.
  • tonic handles gRPC transport, serialization, and HTTP/2.
  • reqwest calls the Sui JSON-RPC endpoint. No heavyweight SDK dependency.

Prerequisites

# macOS
brew install protobuf

# Ubuntu / Debian
sudo apt install -y protobuf-compiler

# Verify
protoc --version

Running

cd rust-api

# Optional: create a .env file
echo 'SUI_RPC_URL=https://fullnode.testnet.sui.io:443' > .env
echo 'LISTEN_ADDR=[::1]:50051' >> .env

# Build and run
cargo run

The server starts on [::1]:50051 by default.

Configuration

Variable Default Description
LISTEN_ADDR [::1]:50051 gRPC server listen address
SUI_RPC_URL https://fullnode.testnet.sui.io:443 Sui JSON-RPC endpoint
RUST_LOG move_course_api=info Log level filter

RPC Endpoints

RPC Description
HealthCheck Returns ok: true and the connected node's protocol version
GetObject Fetches an on-chain object by hex ID
GetBalance Returns the SUI balance (in MIST) for an address
DryRunMoveCall Simulates a Move function call without submitting a transaction
GetEvents Returns events emitted by a specific transaction digest

Testing with grpcurl

# Install grpcurl: https://github.com/fullstorydev/grpcurl
# Note: requires the server to have gRPC reflection enabled, or use the proto file.

# Health check
grpcurl -plaintext -import-path proto -proto move_service.proto \
    '[::1]:50051' move_service.MoveService/HealthCheck

# Get balance
grpcurl -plaintext -import-path proto -proto move_service.proto \
    -d '{"address": "0x..."}' \
    '[::1]:50051' move_service.MoveService/GetBalance

# Get object
grpcurl -plaintext -import-path proto -proto move_service.proto \
    -d '{"object_id": "0x..."}' \
    '[::1]:50051' move_service.MoveService/GetObject

Build & Test

cargo build
cargo test
cargo clippy -- -D warnings
cargo fmt -- --check

Project Structure

rust-api/
├── Cargo.toml              # Dependencies
├── build.rs                # Protobuf code generation
├── proto/
│   └── move_service.proto  # gRPC service definition
├── src/
│   ├── main.rs             # Entrypoint — server startup
│   ├── config.rs           # Environment configuration
│   ├── server.rs           # gRPC handler implementations
│   └── sui_client.rs       # Sui JSON-RPC wrapper
└── README.md

References