Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/generator/template-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ValidationCliError } from '../errors/errors.js';
const BUNDLED_TEMPLATE_DIRECTORIES = {
'basic-app': 'basic-app',
'full-stack': 'full-stack',
'smart-contract': 'smart-contract',
} as const;

type BundledTemplateId = keyof typeof BUNDLED_TEMPLATE_DIRECTORIES;
Expand Down
4 changes: 4 additions & 0 deletions templates/smart-contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target/
.env
.env.*
.DS_Store
16 changes: 16 additions & 0 deletions templates/smart-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[workspace]
resolver = "2"
members = ["contracts/*"]

[workspace.dependencies]
soroban-sdk = "26"

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true
57 changes: 57 additions & 0 deletions templates/smart-contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# {{projectName}}

Generated with the StellarForge `smart-contract` template.

This is an intentionally small, non-custodial Soroban starter. It does not manage assets, balances, authorization, or deployment credentials.

## Requirements

- Rust 1.84 or newer
- `wasm32v1-none` target
- current `stellar` CLI

Install the Rust target when needed:

```bash
rustup target add wasm32v1-none
```

## Test

```bash
cargo test
```

## Build

Use the current Stellar CLI contract workflow:

```bash
stellar contract build
```

The CLI builds contract crates for the `wasm32v1-none` target using the release profile.

## Testnet deployment

Build first, then deploy the generated Wasm with an identity you created outside this repository. Choose an alias that is valid for your local Stellar configuration; `my-contract` is used below only as an example.

```bash
stellar contract deploy \
--wasm <path-to-generated-wasm> \
--source <local-identity> \
--network testnet \
--alias my-contract
```

Invoke the starter after deployment:

```bash
stellar contract invoke \
--id my-contract \
--source <local-identity> \
--network testnet \
-- hello --name StellarForge
```

Do not commit private keys, secret seeds, signing credentials, or production deployment material. Use locally managed Stellar identities or your approved secret-management workflow.
15 changes: 15 additions & 0 deletions templates/smart-contract/contracts/hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "stellarforge-starter-contract"
version = "0.1.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
soroban-sdk = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
15 changes: 15 additions & 0 deletions templates/smart-contract/contracts/hello/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![no_std]

use soroban_sdk::{contract, contractimpl, String};

#[contract]
pub struct Contract;

#[contractimpl]
impl Contract {
pub fn hello(name: String) -> String {
name
}
}

mod test;
14 changes: 14 additions & 0 deletions templates/smart-contract/contracts/hello/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![cfg(test)]

use super::*;
use soroban_sdk::{Env, String};

#[test]
fn returns_the_supplied_greeting_target() {
let env = Env::default();
let contract_id = env.register(Contract, ());
let client = ContractClient::new(&env, &contract_id);
let name = String::from_str(&env, "StellarForge");

assert_eq!(client.hello(&name), name);
}
74 changes: 74 additions & 0 deletions tests/smart-contract-template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { spawnSync } from 'node:child_process';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import { createNewCommand } from '../src/commands/new.js';
import {
createCapturedTerminalOutput,
withTempDirectory,
} from './helpers/index.js';

describe('Smart Contract template', () => {
it('generates a valid Cargo workspace with current Stellar contract guidance and no secrets', () =>
withTempDirectory((root) => {
const captured = createCapturedTerminalOutput();
const command = createNewCommand({
cwd: () => root,
output: captured.output,
});

command.parse([
'node',
'new',
'demo.contract',
'--template',
'smart-contract',
]);

const projectRoot = join(root, 'demo.contract');
const rootManifest = readFileSync(
join(projectRoot, 'Cargo.toml'),
'utf8',
);
const contractManifest = readFileSync(
join(projectRoot, 'contracts', 'hello', 'Cargo.toml'),
'utf8',
);
const readme = readFileSync(join(projectRoot, 'README.md'), 'utf8');

expect(
existsSync(join(projectRoot, 'contracts', 'hello', 'src', 'lib.rs')),
).toBe(true);
expect(
existsSync(join(projectRoot, 'contracts', 'hello', 'src', 'test.rs')),
).toBe(true);
expect(rootManifest).toContain('soroban-sdk = "26"');
expect(rootManifest).not.toContain('wasm32v1-none');
expect(contractManifest).toContain(
'name = "stellarforge-starter-contract"',
);
expect(contractManifest).not.toContain('demo.contract');
expect(readme).toContain('# demo.contract');
expect(readme).toContain('stellar contract build');
expect(readme).toContain('stellar contract deploy');
expect(readme).toContain('stellar contract invoke');
expect(readme).toContain('--network testnet');
expect(readme).not.toMatch(/S[A-Z0-9]{55}/);
expect(captured.stdoutText()).toContain(
'Created demo.contract from smart-contract',
);

const metadata = spawnSync(
'cargo',
['metadata', '--no-deps', '--format-version=1'],
{
cwd: projectRoot,
encoding: 'utf8',
shell: false,
},
);

expect(metadata.status, metadata.stderr).toBe(0);
expect(metadata.stdout).toContain('stellarforge-starter-contract');
}));
});
Loading