Skip to content

Latest commit

 

History

History
137 lines (103 loc) · 2.87 KB

File metadata and controls

137 lines (103 loc) · 2.87 KB

RustChain API Walkthrough

First steps for developers integrating with RustChain.


Quick API Test

1. Health Check

curl -sk https://50.28.86.131/health

Response:

{
  "ok": true,
  "version": "2.2.1-rip200",
  "uptime_s": 200000
}

2. Get Epoch Info

curl -sk https://50.28.86.131/epoch

Response:

{
  "epoch": 95,
  "slot": 12345,
  "height": 67890
}

3. Check Balance

curl -sk "https://50.28.86.131/wallet/balance?miner_id=Ivan-houzhiwen"

Response:

{
  "amount_i64": 155000000,
  "amount_rtc": 155.0,
  "miner_id": "Ivan-houzhiwen"
}

Signed Transfer

The transfer endpoint requires a signed transaction.

Endpoint

POST /wallet/transfer/signed

Request Body

{
  "from": "sender_wallet_id",
  "to": "recipient_wallet_id", 
  "amount": 10,
  "fee": 0.001,
  "signature": "hex_encoded_signature",
  "timestamp": 1234567890
}

Field Explanation

Field Type Description
from string Sender's RustChain wallet ID
to string Recipient's RustChain wallet ID
amount integer Amount in RTC (smallest unit)
fee float Transaction fee
signature hex string Ed25519 signature of the transfer payload
timestamp integer Unix timestamp for replay protection

Important Notes

  1. Wallet IDs are NOT external addresses - RustChain uses its own wallet system (e.g., Ivan-houzhiwen), not Ethereum or Solana addresses.

  2. TLS certificates - RustChain nodes use self-signed certificates. For production use, place the node's certificate at ~/.rustchain/node_cert.pem and the requests library will automatically use it (default verify=True). For local testing with a self-signed certificate that is not pinned, you may temporarily set verify=False but be aware of MITM risks. The recommended pattern is to use the shared tls_config module from the RustChain codebase: from node.tls_config import get_tls_session; session = get_tls_session().

  3. Amount is in smallest unit - 1 RTC = 1,000,000 smallest units.


Example: Python

import requests
import json

# Check balance
response = requests.get(
    "https://50.28.86.131/wallet/balance",
    params={"miner_id": "Ivan-houzhiwen"},
)
print(f"Balance: {response.json()['amount_rtc']} RTC")

# Transfer (requires signature)
transfer_data = {
    "from": "sender_wallet",
    "to": "recipient_wallet",
    "amount": 1000000,  # 1 RTC
    "fee": 1000,
    "signature": "...",
    "timestamp": 1234567890
}
response = requests.post(
    "https://50.28.86.131/wallet/transfer/signed",
    json=transfer_data,
)
print(response.json())

Reference

  • Node: https://50.28.86.131
  • Explorer: https://50.28.86.131/explorer
  • Health: https://50.28.86.131/health

Ref: #701