This repository uses the recommended structure for a Soroban project:
.
├── contracts
│ └── hello_world
│ ├── src
│ │ ├── lib.rs
│ │ └── test.rs
│ └── Cargo.toml
├── Cargo.toml
└── README.md
- New Soroban contracts can be put in
contracts
, each in their own directory. There is already ahello_world
contract in there to get you started. - If you initialized this project with any other example contracts via
--with-example
, those contracts will be in thecontracts
directory as well. - Contracts should have their own
Cargo.toml
files that rely on the top-levelCargo.toml
workspace for their dependencies. - Frontend libraries can be added to the top-level directory as well. If you initialized this project with a frontend template via
--frontend-template
you will have those files already included.
A Frontend Template suitable for use with soroban contract init --frontend-template
, powered by Astro.
cp .env.example .env
npm install
npm run dev
If you look in package.json, you'll see that the start
& dev
scripts first run the initialize.js
script. This script loops over all contracts in contracts/*
and, for each:
- Deploys to a local network (needs to be running with
docker run
orsoroban network start
) - Saves contract IDs to
.soroban/contract-ids
- Generates TS bindings for each into the
packages
folder, which is set up as an npm workspace - Create a file in
src/contracts
that imports the contract client and initializes it for thestandalone
network.
You're now ready to import these initialized contract clients in your Astro templates or your React, Svelte, Vue, Alpine, Lit, and whatever else JS files. You can see an example of this in index.astro.