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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ members = [
"contracts/course/course_access",
"contracts/user_profile",
"contracts/test_contract",
"contracts/user_management"
"contracts/user_management",
"contracts/schema_export"
]

[workspace.dependencies]
Expand Down
15 changes: 15 additions & 0 deletions contracts/schema_export/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "schema_export"
version = "0.0.0"
edition = "2021"
publish = false

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

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

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

use soroban_sdk::{contracttype, Env, String, Vec};

/// Helper module for exporting contract schemas
pub mod schema_export {
use super::*;

/// Export contract metadata for frontend consumption
#[contracttype]
pub struct ContractMetadata {
pub name: String,
pub version: String,
pub methods: Vec<MethodInfo>,
}

#[contracttype]
pub struct MethodInfo {
pub name: String,
pub params: Vec<ParamInfo>,
pub returns: String,
}

#[contracttype]
pub struct ParamInfo {
pub name: String,
pub type_name: String,
pub required: bool,
}
}
23 changes: 23 additions & 0 deletions schemas/contracts_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"contracts": {
"course_access": {
"wasm": "target/wasm32v1-none/release/course_access.wasm",
"schema": "schemas/course_access_schema.json",
"docs": "schemas/course_access_docs.md",
"typescript": "schemas/course_access-ts/"
},
"course_registry": {
"wasm": "target/wasm32v1-none/release/course_registry.wasm",
"schema": "schemas/course_registry_schema.json",
"docs": "schemas/course_registry_docs.md",
"typescript": "schemas/course_registry-ts/"
},
"user_management": {
"wasm": "target/wasm32v1-none/release/user_management.wasm",
"schema": "schemas/user_management_schema.json",
"docs": "schemas/user_management_docs.md",
"typescript": "schemas/user_management-ts/"
}
},
"generated_at": "2025-10-03T10:48:29Z"
}
2 changes: 2 additions & 0 deletions schemas/course_access-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
out/
54 changes: 54 additions & 0 deletions schemas/course_access-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# course_access-ts JS

JS library for interacting with [Soroban](https://soroban.stellar.org/) smart contract `course_access-ts` via Soroban RPC.

This library was automatically generated by Soroban CLI using a command similar to:

```bash
soroban contract bindings ts \
--rpc-url INSERT_RPC_URL_HERE \
--network-passphrase "INSERT_NETWORK_PASSPHRASE_HERE" \
--contract-id INSERT_CONTRACT_ID_HERE \
--output-dir ./path/to/course_access-ts
```

The network passphrase and contract ID are exported from [index.ts](./src/index.ts) in the `networks` constant. If you are the one who generated this library and you know that this contract is also deployed to other networks, feel free to update `networks` with other valid options. This will help your contract consumers use this library more easily.

# To publish or not to publish

This library is suitable for publishing to NPM. You can publish it to NPM using the `npm publish` command.

But you don't need to publish this library to NPM to use it. You can add it to your project's `package.json` using a file path:

```json
"dependencies": {
"course_access-ts": "./path/to/this/folder"
}
```

However, we've actually encountered [frustration](https://github.com/stellar/soroban-example-dapp/pull/117#discussion_r1232873560) using local libraries with NPM in this way. Though it seems a bit messy, we suggest generating the library directly to your `node_modules` folder automatically after each install by using a `postinstall` script. We've had the least trouble with this approach. NPM will automatically remove what it sees as erroneous directories during the `install` step, and then regenerate them when it gets to your `postinstall` step, which will keep the library up-to-date with your contract.

```json
"scripts": {
"postinstall": "soroban contract bindings ts --rpc-url INSERT_RPC_URL_HERE --network-passphrase \"INSERT_NETWORK_PASSPHRASE_HERE\" --id INSERT_CONTRACT_ID_HERE --name course_access-ts"
}
```

Obviously you need to adjust the above command based on the actual command you used to generate the library.

# Use it

Now that you have your library up-to-date and added to your project, you can import it in a file and see inline documentation for all of its exported methods:

```js
import { Contract, networks } from "course_access-ts"

const contract = new Contract({
...networks.futurenet, // for example; check which networks this library exports
rpcUrl: '...', // use your own, or find one for testing at https://soroban.stellar.org/docs/reference/rpc#public-rpc-providers
})

contract.|
```

As long as your editor is configured to show JavaScript/TypeScript documentation, you can pause your typing at that `|` to get a list of all exports and inline-documentation for each. It exports a separate [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function for each method in the smart contract, with documentation for each generated from the comments the contract's author included in the original source code.
17 changes: 17 additions & 0 deletions schemas/course_access-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.0.0",
"name": "course_access-ts",
"type": "module",
"exports": "./dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "tsc"
},
"dependencies": {
"@stellar/stellar-sdk": "^14.1.1",
"buffer": "6.0.3"
},
"devDependencies": {
"typescript": "^5.6.2"
}
}
Loading
Loading