James Bachini

Scaffold Stellar | A Boilerplate For Stellar Developers

Scaffold Stellar

If a single command could spin up a Stellar contract, connect it to a React front end, hot reload every edit, and hand you push button deployment to Stellar testnet, would you finally ship that web3 idea?

Scaffold Stellar from Aha Labs promises exactly that.

James On YouTube

Stellar’s smart contract runtime brings Rust performance to a payments network, yet developers still struggle through wasm compilation flags, and mismatched SDK versions.

Scaffold Stellar attacks those choke points with convention over configuration: standardised folder layouts, sane defaults baked into CLI flags, and procedural macros that turn ten lines of Rust boilerplate into a single attribute.

Setting Up Scaffold Stellar

Installation is deliberately boring: a single cargo call installs stellar-scaffold-cli crate in a couple of minutes.

cargo install stellar-scaffold-cli

We can then edit the .env.example file and add in testnet support using the network passphrase and RPC url from: https://developers.stellar.org/docs/networks

Save the file as .env and it should look something like this:

PUBLIC_STELLAR_NETWORK="testnet"
PUBLIC_STELLAR_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
PUBLIC_STELLAR_RPC_URL="https://soroban-testnet.stellar.org"

From here we can startup a vite live dev server using the following commands.

npm install
npm run dev

Now we can open up a web browser at http://localhost:5173 showing the boilerplate frontend.

scaffold stellar

This is running locally using a dev web server, VITE v6.3.5.

There is a tool for hot reloading of smart contracts using

stellar scaffold watch

Use your favourite code editor to open contracts/hello_world/src/lib.rs

This is the starter contract which is linked up to the frontend.

Scaffold Stellar takes care of compiling your smart contract packages automatically, making them easy to import into your frontend.

import soroban_hello_world_contract from "./contracts/soroban_hello_world_contract.ts";

Once imported, you can interact with contract methods like so:

const statusMessage = await soroban_hello_world_contract.hello({ to: "world" });

This allows you to call contract functions directly within your React components. If your contract emits events, you can use the useSubscription hook found in the hooks/ directory to listen for them in real-time.

The project comes pre-integrated with Stellar Wallet Kit.

You can access wallet functionality using the useWallet hook, which provides methods to connect a wallet and retrieve account details within your UI components.


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.


Posted

in

, , , , , , ,

by