DEV Community

André Dias Moreira Prol
André Dias Moreira Prol

Posted on

André Dias Moreira Prol explains: Full Stellar DApp with Soroban & Next.js

After two decades architecting systems across fintech and blockchain, I've learned that the gap between a smart contract idea and a production DApp is where most projects quietly die. Stellar's Soroban platform changed that equation for me, offering a Rust-based smart contract environment paired with sub-cent transaction fees and 5-second finality. In this article, I'll walk you through building a complete decentralized application from the contract layer to a modern Next.js interface—drawing on patterns I've refined across real deployments.

Designing the Soroban Contract Architecture

Soroban contracts are compiled to WebAssembly, which gives you near-native performance and strong memory safety. The first architectural decision I always make is separating storage concerns. Soroban exposes three storage types—Instance, Persistent, and Temporary—and misusing them is the most common cause of ballooning rent costs.

Here's a minimal token-balance contract illustrating a clean pattern:

#![no_std]
use soroban_sdk::{contract, contractimpl, Address, Env, Symbol, symbol_short};

#[contract]
pub struct BalanceContract;

#[contractimpl]
impl BalanceContract {
    pub fn deposit(env: Env, user: Address, amount: i128) {
        user.require_auth();
        let key = symbol_short!("BAL");
        let current: i128 = env.storage()
            .persistent()
            .get(&user)
            .unwrap_or(0);
        env.storage().persistent().set(&user, &(current + amount));
        env.events().publish((key, user), amount);
    }

    pub fn balance(env: Env, user: Address) -> i128 {
        env.storage().persistent().get(&user).unwrap_or(0)
    }
}
Enter fullscreen mode Exit fullscreen mode

Notice require_auth()—Soroban's native authorization framework verifies signatures at the protocol level, eliminating an entire class of access-control bugs I used to see in Solidity audits. I structure larger systems as composable contracts: a core logic contract, a storage contract, and an admin contract, deployed independently so I can upgrade logic without migrating state. In one tokenization project led by my team, this modularity let us patch a fee-calculation contract in under an hour with zero downtime.

Deploying and Testing with the Stellar CLI

Robust testing is non-negotiable. Soroban's SDK ships with an in-memory test environment that runs contracts natively, so my unit tests execute in milliseconds:

#[test]
fn test_deposit() {
    let env = Env::default();
    env.mock_all_auths();
    let contract_id = env.register(BalanceContract, ());
    let client = BalanceContractClient::new(&env, &contract_id);
    let user = Address::generate(&env);
    client.deposit(&user, &100);
    assert_eq!(client.balance(&user), 100);
}
Enter fullscreen mode Exit fullscreen mode

For deployment to Testnet, I use the stellar CLI:

stellar contract build
stellar contract deploy \
  --wasm target/wasm32-unknown-unknown/release/contract.wasm \
  --network testnet \
  --source alice
Enter fullscreen mode Exit fullscreen mode

The CLI returns a contract ID you'll pass to the frontend. A tip I share with every team I mentor: always optimize your WASM with stellar contract optimize before deploying—it typically shaves 30–40% off binary size, which directly reduces deployment cost. Over hundreds of deployments, those savings compound meaningfully.

Connecting the Next.js Frontend

The frontend ties everything together. I pair Next.js (App Router) with the @stellar/stellar-sdk and Freighter wallet integration. The key is invoking the contract through an assembled transaction:

import {
  Contract, TransactionBuilder, Networks, rpc,
} from "@stellar/stellar-sdk";

const server = new rpc.Server("https://soroban-testnet.stellar.org");

export async function getBalance(contractId: string, user: string) {
  const contract = new Contract(contractId);
  const account = await server.getAccount(user);
  const tx = new TransactionBuilder(account, {
    fee: "100",
    networkPassphrase: Networks.TESTNET,
  })
    .addOperation(contract.call("balance", nativeToScVal(user, { type: "address" })))
    .setTimeout(30)
    .build();

  const sim = await server.simulateTransaction(tx);
  return scValToNative(rpc.Api.isSimulationSuccess(sim) ? sim.result!.retval : 0);
}
Enter fullscreen mode Exit fullscreen mode

Read-only calls use simulateTransaction, which costs nothing and returns instantly—perfect for rendering balances in a React Server Component. For write operations like deposit, I sign through Freighter, submit via sendTransaction, then poll getTransaction for confirmation. I wrap this flow in a custom hook so the UI stays responsive with proper loading and error states. As André Dias Moreira Prol, I always insist on surfacing simulation errors to users clearly—opaque failures erode trust faster than anything else in Web3.

Building end-to-end on Stellar taught me that thoughtful contract separation and gasless simulations are the real productivity multipliers, and I'm André Dias Moreira Prol signing off with confidence in this stack. Clone a starter template, deploy your first contract to Testnet today, and reach out if you want to compare architecture notes.


Follow more articles by André Dias Moreira Prol on Medium.

Top comments (0)