跳到主要内容

快速入门

在不到 5 分钟内启动本地 Savitri 节点并发送您的第一笔交易。

1. 生成密钥

# 生成一个节点密钥对
cargo run -p savitri-sdk --bin key_generator

此命令输出一个 ed25519 密钥对:

  • 私钥:64 个十六进制字符(32 字节)—— 请妥善保管,切勿泄露
  • 公钥:64 个十六进制字符(32 字节)—— 这就是您的地址

2. 启动轻节点

cargo run -p savitri-lightnode --bin lightnode -- \
--listen-port 4001 \
--tx-interval-secs 2 \
--block-interval-secs 10 \
--max-block-txs 32

轻节点启动后开始监听端口 4001(P2P)和 8545(RPC)。

3. 检查节点健康状态

curl -X POST http://localhost:8545/rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "savitri_health",
"params": [],
"id": 1
}'

响应:

{
"jsonrpc": "2.0",
"result": {
"status": "ok",
"service": "savitri-rpc",
"mode": "lightnode"
},
"id": 1
}

4. 获取区块高度

curl -X POST http://localhost:8545/rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "savitri_blockNumber",
"params": [],
"id": 2
}'

5. 查询账户余额

curl -X POST http://localhost:8545/rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "savitri_getAccount",
"params": ["YOUR_ADDRESS_HEX_64_CHARS"],
"id": 3
}'

6. 领取测试网代币(水龙头)

在测试网上免费领取 SAVT 代币:

curl -X POST http://localhost:8545/rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "savitri_faucetClaim",
"params": ["YOUR_ADDRESS_HEX_64_CHARS"],
"id": 4
}'

响应:

{
"jsonrpc": "2.0",
"result": {
"result": {
"tx_hash": "0x...",
"amount": "5000000000000000000"
}
},
"id": 4
}

水龙头每次发放 5 SAVT,冷却时间为 24 小时。

7. 使用 SDK(Rust)

Cargo.toml 中添加依赖:

[dependencies]
savitri-sdk = { path = "../savitri-sdk" }
tokio = { version = "1", features = ["full"] }
use savitri_sdk::{RpcClient, Wallet, TransactionBuilder};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = RpcClient::from_url("http://localhost:8545")?;

// 健康检查
let health = client.health().await?;
println!("Node mode: {}", health.mode);

// 区块高度
let height = client.get_block_number().await?;
println!("Block height: {}", height);

// 创建钱包并检查余额
let wallet = Wallet::new();
let account = client.get_account(wallet.address()).await?;
println!("Address: {}", wallet.address());
println!("Balance: {}", account.balance);

Ok(())
}

下一步