Skip to main content

Tutorial: Deploy Your First SAVITRI-20 Token

This tutorial walks you through deploying a fungible token on the Savitri Network using the SDK.

Prerequisites

  • A running Savitri lightnode (see Quick Start)
  • Rust toolchain installed
  • A funded wallet (use the testnet faucet)

1. Project Setup

Create a new Rust project:

cargo new my-savitri-token
cd my-savitri-token

Add dependencies to Cargo.toml:

[dependencies]
savitri-sdk = { path = "../savitri-sdk" }
tokio = { version = "1", features = ["full"] }
anyhow = "1"
hex = "0.4"

2. Create a Wallet

use savitri_sdk::{Wallet, RpcClient};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create or import a wallet
let wallet = Wallet::new();
println!("Your address: {}", wallet.address());

// Connect to local node
let client = RpcClient::from_url("http://localhost:8545")?;

// Check if node is running
let health = client.health().await?;
println!("Connected to {} ({})", health.service, health.mode);

Ok(())
}

3. Fund Your Wallet

Claim testnet tokens via the faucet:

let claim = client.faucet_claim(wallet.address()).await?;
println!("Received {} SAVT (tx: {})", claim.amount, claim.tx_hash);

// Wait for confirmation
tokio::time::sleep(std::time::Duration::from_secs(10)).await;

// Verify balance
let account = client.get_account(wallet.address()).await?;
println!("Balance: {} (nonce: {})", account.balance, account.nonce);

4. Deploy the Token Contract

Token deployment is a transaction with to = None and the initialization data in data:

use savitri_sdk::TransactionBuilder;

// Encode token initialization parameters
fn encode_token_init(name: &str, symbol: &str, initial_supply: u128) -> Vec<u8> {
let mut data = b"initialize_savitri20".to_vec();
data.push(0); // separator

// Name (length-prefixed)
data.extend_from_slice(&(name.len() as u32).to_le_bytes());
data.extend_from_slice(name.as_bytes());

// Symbol (length-prefixed)
data.extend_from_slice(&(symbol.len() as u32).to_le_bytes());
data.extend_from_slice(symbol.as_bytes());

// Initial supply (u128 LE)
data.extend_from_slice(&initial_supply.to_le_bytes());

data
}

// Build deploy transaction
let nonce = client.get_nonce(wallet.address()).await?;

let deploy_data = encode_token_init(
"My Token", // name
"MTK", // symbol
1_000_000_000_000_000_000_000_000, // 1M tokens (18 decimals)
);

let deploy_tx = TransactionBuilder::new()
// No .to() — indicates contract deployment
.data(deploy_data)
.value(0)
.nonce(nonce)
.fee(5_000_000_000_000_000) // 0.005 SAVT contract fee
.build_and_sign(&wallet)?;

println!("Deploy TX built. Contract will be created at a derived address.");

5. Interact with the Token

Once deployed, use the ContractClient to interact:

use savitri_sdk::ContractClient;

let contract = ContractClient::from_url_and_wallet(
"http://localhost:8545",
wallet.clone(),
)?;

// Transfer tokens
let tx_hash = contract.call_contract(
&token_contract_address,
b"transfer",
&encode_transfer(&recipient_address, 1000_000_000_000_000_000), // 1000 tokens
Some(0),
).await?;
println!("Transfer TX: {}", tx_hash);

6. Check Token Balance

// Via RPC
let balance = client.call_raw(
"account_getTokenBalance",
serde_json::json!([wallet.address(), token_contract_address]),
).await?;
println!("Token balance: {}", balance);

Token Standards Quick Reference

StandardUse CaseKey Functions
SAVITRI-20Fungible tokenstransfer, approve, transferFrom
SAVITRI-721NFTsmint, transferFrom, tokenURI
SAVITRI-1155Multi-assetsafeTransferFrom, balanceOfBatch

Fee Reference

OperationFee (SAVT)
Token deploy0.005
Token transfer0.005
Token approve0.005
NFT mint0.005
Batch transfer0.005

Amounts and Decimals

All Savitri tokens use 18 decimals:

1 token     = 1_000_000_000_000_000_000  (10^18)
0.001 token = 1_000_000_000_000_000 (10^15)
1M tokens = 1_000_000_000_000_000_000_000_000 (10^24)

Next Steps