Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Commit c2924f0

Browse files
chadohwillemneal
andauthored
feat: switch from soroban-react to generated libs (#117)
* feat: switch from soroban-react to generated libs * feat: add ft-contract source; rm `../examples` - don't use `soroban lab token` to generate/deploy token - instead, copy example token from examples repo - remove `../examples` reference in `generate` script - add `target/bin/soroban` with pinned version of `soroban` to be used throughout initialize.sh * fix: use workspace dependency versions; update sdk * feat: no more embedding secret keys This copies ideas from the contract in https://github.com/AhaLabs/soroban-abundance-token, allowing anyone to mint themselves tokens. Now this can be used from the frontend directly, so we no longer need to embed the admin's secret key in the JS. Hooray! Upon closer inspection, we didn't need any of those constants anymore, since the contract IDs are embedded in the token libraries. * fix: add mint_100 and comment out events * fix: start tryna fix event subscriptions * fix: update UI after minting 100 ABND * fix: signAndSend `deposit`; fix modal; update form The whole page no longer reloads after a pledge. Instead, FormPledge now takes an `onPledge` param, which it calls after the pledge succeeds. The now-somewhat-awkward `resultSubmit` has also been filled back out to match what the modal expects, so the modal looks correct. * docs: update AlmostUnnecessaryProvider comment * build: allow newer node versions; improve package name * build: generate contract clients * build: fill in .soroban-example-dapp/* first The CI script needs the values there before it can generate the libraries, of course. And the `token_admin*` stuff isn't needed anymore. * build: install locked CLI version with alias * build: build contracts before generating clients * build: s/run-script/run/ Replace `run-script` with the much more common alias `run` to match the rest of the workflow file * build: make convert.ts pass strict; exclude target/ from type checking * build: use node 18 in CI * build: update lockfile; cat lockfiles during build * build: switch to yarn; will it work better? * build: omg yarn works with relative paths but not file: * build: rm busted debug steps; update docs for yarn * build: s/yarn ci/yarn install --frozen-lockfile * build: back to npm we go * build: switch to postinstall script * build: rm outdated build step * build: warn, don't deny, on clippy complaints and add .cargo/config.toml to match CI settings * feat: use freighter-api@1.5 * feat: straightforward copy/paste of subscribe logic This gets the subscriptions working, and finally breaks all dependence on the @soroban-react packages. The logic is a little confusing, but it works! * feat: move subscribe logic to useSubscription hook This is a hook that can be copy/pasted into other React projects that need such functionality, to work alongside their generated libraries until these generated libraries expose subscription logic natively. * fix: update all relevant UI after pledging * fix: avoid Freighter error if not yet connected * fix: can't default build to wasm because tests * build: use latest soroban-cli Uses the version with updated freighter-api stellar/stellar-cli#708 * build: use latest cli/soroban-client; rm stellar-base pin * build: use latest CLI rev from stellar repo * fix: deal with undefined case * build: rm RUSTFLAGS from Makefile Since d771b3f, the default settings are now set in `.cargo/config.toml` * fix: allow using standalone Everything looks correct, but when running the app it fails with: Error: Cannot connect to insecure soroban-rpc server * build: update freighter-api * build: update pinned soroban-cli version * build(ci): stub .soroban-example-dapp/network * fix: add 'await' --------- Co-authored-by: Willem Wyndham <willem@ahalabs.dev>
1 parent 6bf4bdd commit c2924f0

39 files changed

Lines changed: 1555 additions & 4738 deletions

.cargo/config.toml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# paths = ["/path/to/override"] # path dependency overrides
2+
3+
[alias] # command aliases
4+
install_soroban = "install --git https://github.com/stellar/soroban-tools --rev 2b343d3e6afdb5eff54fb03622627cd55e785358 --root ./target soroban-cli --debug"
5+
b = "build --target wasm32-unknown-unknown --release"
6+
# c = "check"
7+
# t = "test"
8+
# r = "run"
9+
# rr = "run --release"
10+
# recursive_example = "rr --example recursions"
11+
# space_example = ["run", "--release", "--", "\"command list\""]
12+
13+
[build]
14+
# jobs = 1 # number of parallel jobs, defaults to # of CPUs
15+
# rustc = "rustc" # the rust compiler tool
16+
# rustc-wrapper = "…" # run this wrapper instead of `rustc`
17+
# rustc-workspace-wrapper = "…" # run this wrapper instead of `rustc` for workspace members
18+
# rustdoc = "rustdoc" # the doc generator tool
19+
# target = "wasm32-unknown-unknown" # build for the target triple (ignored by `cargo install`)
20+
# target-dir = "target" # path of where to place all generated artifacts
21+
rustflags = [ # set these to match .github/workflows/rust.yml
22+
"-Wclippy::all", # warn for all clippy lints
23+
"-Wclippy::pedantic", # warn for pedantic clippy lints
24+
] # custom flags to pass to all compiler invocations
25+
# rustdocflags = ["…", "…"] # custom flags to pass to rustdoc
26+
# incremental = true # whether or not to enable incremental compilation
27+
# dep-info-basedir = "…" # path for the base directory for targets in depfiles
28+
29+
# [doc]
30+
# browser = "chromium" # browser to use with `cargo doc --open`,
31+
# # overrides the `BROWSER` environment variable
32+
33+
# [env]
34+
# # Set ENV_VAR_NAME=value for any process run by Cargo
35+
# ENV_VAR_NAME = "value"
36+
# # Set even if already present in environment
37+
# ENV_VAR_NAME_2 = { value = "value", force = true }
38+
# # Value is relative to .cargo directory containing `config.toml`, make absolute
39+
# ENV_VAR_NAME_3 = { value = "relative/path", relative = true }
40+
41+
# [future-incompat-report]
42+
# frequency = 'always' # when to display a notification about a future incompat report
43+
44+
# [cargo-new]
45+
# vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')
46+
47+
# [http]
48+
# debug = false # HTTP debugging
49+
# proxy = "host:port" # HTTP proxy in libcurl format
50+
# ssl-version = "tlsv1.3" # TLS version to use
51+
# ssl-version.max = "tlsv1.3" # maximum TLS version
52+
# ssl-version.min = "tlsv1.1" # minimum TLS version
53+
# timeout = 30 # timeout for each HTTP request, in seconds
54+
# low-speed-limit = 10 # network timeout threshold (bytes/sec)
55+
# cainfo = "cert.pem" # path to Certificate Authority (CA) bundle
56+
# check-revoke = true # check for SSL certificate revocation
57+
# multiplexing = true # HTTP/2 multiplexing
58+
# user-agent = "…" # the user-agent header
59+
60+
# [install]
61+
# root = "/some/path" # `cargo install` destination directory
62+
63+
# [net]
64+
# retry = 2 # network retries
65+
# git-fetch-with-cli = true # use the `git` executable for git operations
66+
# offline = true # do not access the network
67+
68+
# [net.ssh]
69+
# known-hosts = ["..."] # known SSH host keys
70+
71+
# [patch.<registry>]
72+
# # Same keys as for [patch] in Cargo.toml
73+
74+
# [profile.<name>] # Modify profile settings via config.
75+
# inherits = "dev" # Inherits settings from [profile.dev].
76+
# opt-level = 0 # Optimization level.
77+
# debug = true # Include debug info.
78+
# split-debuginfo = '...' # Debug info splitting behavior.
79+
# debug-assertions = true # Enables debug assertions.
80+
# overflow-checks = true # Enables runtime integer overflow checks.
81+
# lto = false # Sets link-time optimization.
82+
# panic = 'unwind' # The panic strategy.
83+
# incremental = true # Incremental compilation.
84+
# codegen-units = 16 # Number of code generation units.
85+
# rpath = false # Sets the rpath linking option.
86+
# [profile.<name>.build-override] # Overrides build-script settings.
87+
# # Same keys for a normal profile.
88+
# [profile.<name>.package.<name>] # Override profile for a package.
89+
# # Same keys for a normal profile (minus `panic`, `lto`, and `rpath`).
90+
91+
# [registries.<name>] # registries other than crates.io
92+
# index = "…" # URL of the registry index
93+
# token = "…" # authentication token for the registry
94+
95+
# [registry]
96+
# default = "…" # name of the default registry
97+
# token = "…" # authentication token for crates.io
98+
99+
# [source.<name>] # source definition and replacement
100+
# replace-with = "…" # replace this source with the given named source
101+
# directory = "…" # path to a directory source
102+
# registry = "…" # URL to a registry source
103+
# local-registry = "…" # path to a local registry source
104+
# git = "…" # URL of a git repository source
105+
# branch = "…" # branch name for the git repository
106+
# tag = "…" # tag name for the git repository
107+
# rev = "…" # revision for the git repository
108+
109+
# [target.<triple>]
110+
# linker = "…" # linker to use
111+
# runner = "…" # wrapper to run executables
112+
# rustflags = ["…", "…"] # custom flags for `rustc`
113+
114+
# [target.<cfg>]
115+
# runner = "…" # wrapper to run executables
116+
# rustflags = ["…", "…"] # custom flags for `rustc`
117+
118+
# [target.<triple>.<links>] # `links` build script override
119+
# rustc-link-lib = ["foo"]
120+
# rustc-link-search = ["/path/to/foo"]
121+
# rustc-flags = ["-L", "/some/path"]
122+
# rustc-cfg = ['key="value"']
123+
# rustc-env = {key = "value"}
124+
# rustc-cdylib-link-arg = ["…"]
125+
# metadata_key1 = "value"
126+
# metadata_key2 = "value"
127+
128+
# [term]
129+
# quiet = false # whether cargo output is quiet
130+
# verbose = false # whether cargo provides verbose output
131+
# color = 'auto' # whether cargo colorizes output
132+
# progress.when = 'auto' # whether cargo shows progress bar
133+
# progress.width = 80 # width of progress bar

.github/workflows/nodejs.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ jobs:
2222
- uses: stellar/actions/rust-cache@main
2323
- run: rustup update
2424
- run: rustup target add wasm32-unknown-unknown
25-
- run: cargo install --target-dir ~/.cargo/target --locked --version 0.8.0 soroban-cli
26-
- name: Use Node.js 17.x
27-
uses: actions/setup-node@v3
25+
- run: make build
26+
- run: cargo install_soroban
27+
- uses: actions/setup-node@v3
2828
with:
29-
node-version: 17.x
29+
node-version: 18.x
3030
cache: 'npm'
31-
- run: npm ci
3231
- run: |
3332
mkdir -p .soroban-example-dapp
34-
echo 'a9ab643486dc0dbcdc1485e6589e8bb3bcbbd8e69ad66c703556b4d6645a6dc8' > .soroban-example-dapp/token_id
35-
echo '42798d5db884626e57f96630e7d02ba8210b4629d2959ef79ebb9e6538676ef9' > .soroban-example-dapp/crowdfund_id
36-
echo 'GDT2NORMZF6S2T4PT4OBJJ43OPD3GPRNTJG3WVVFB356TUHWZQMU6C3U' > .soroban-example-dapp/token_admin_address
37-
echo 'SAKCFFFNCE7XAWYMYVRZQYKUK6KMUCDIINLWISJYTMYJLNR2QLCDLFVT' > .soroban-example-dapp/token_admin_secret
38-
- run: npm run-script build
33+
echo 'futurenet' > .soroban-example-dapp/network
34+
echo 'CC757WDV3G442WQCNPNOA2UEXOC7UJD5VP4BLLCRDW5LRM6UZZR6ISVU' > .soroban-example-dapp/abundance_token_id
35+
echo 'CCHCPXECLYGX4QU34ZZOHP6C6KVAPIDTUNPIUA6GF4SP6ECFF5BX57OG' > .soroban-example-dapp/crowdfund_id
36+
- run: npm ci
37+
- run: npm run build

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
pull_request:
77

88
env:
9-
RUSTFLAGS: -Dwarnings -Dclippy::all -Dclippy::pedantic
9+
RUSTFLAGS: -Wclippy::all -Wclippy::pedantic
1010

1111
jobs:
1212

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
resolver = "2"
33

44
members = [
5-
"contracts/crowdfund",
5+
"contracts/*",
66
]
77

88
[profile.release]
@@ -15,11 +15,6 @@ panic = "abort"
1515
codegen-units = 1
1616
lto = true
1717

18-
[workspace.dependencies.soroban-sdk]
19-
version = "0.8.2"
20-
21-
22-
23-
24-
25-
18+
[workspace.dependencies]
19+
soroban-sdk = "0.8.4"
20+
soroban-token-sdk = "0.8.4"

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ ENV PATH="$PATH:/root/.cargo/bin"
1212
RUN rustup target add wasm32-unknown-unknown
1313

1414
RUN apt install -y build-essential
15-
RUN cargo install --locked --version 0.8.0 soroban-cli
1615
# WORKDIR /
1716
RUN mkdir /workspace
1817
WORKDIR /workspace

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
all: check build test
22

3-
export RUSTFLAGS=-Dwarnings -Dclippy::all -Dclippy::pedantic
43
CARGO_BUILD_TARGET?=wasm32-unknown-unknown
54

65
test: fmt

README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Getting Started
1212
Install Dependencies
1313
--------------------
1414

15-
1. `soroban-cli v0.8.0`. See https://soroban.stellar.org/docs/getting-started/setup#install-the-soroban-cli
15+
1. `soroban-cli`. See https://soroban.stellar.org/docs/getting-started/setup#install-the-soroban-cli, but instead of `cargo install soroban-cli`, run `cargo install_soroban`. This is an alias set up in [.cargo/config.toml](./.cargo/config.toml), which pins the local soroban-cli to a specific version. If you add `./target/bin/` [to your PATH](https://linuxize.com/post/how-to-add-directory-to-path-in-linux/), then you'll automatically use this version of `soroban-cli` when you're in this directory.
1616
2. If you want to run everything locally: `docker` (you can run both Standalone and Futurenet backends with it)
17-
3. `Node.js v17`
17+
3. Node.js v18
1818
4. [Freighter Wallet](https://www.freighter.app/)[v5.0.2](https://github.com/stellar/freighter/releases/tag/2.9.1). Or from the Firefox / Chrome extension store. Once installed, enable "Experimental Mode" in the settings (gear icon).
1919
5. If you want to run everything locally, build the `soroban-preview` docker image:
2020

@@ -33,9 +33,9 @@ You have three options: 1. Deploy on [Futurenet](https://soroban.stellar.org/doc
3333

3434
1. Deploy the contracts and initialize them
3535

36-
./initialize.sh futurenet
36+
npm run setup
3737

38-
This will create a `token-admin` identity for you (`soroban config identity create token-admin`) and deploy a Fungible Token contract as well as the [crowdfund contract](./contracts/crowdfund), with this account as admin.
38+
This runs `./initialize.sh futurenet` behind the scenes, which will create a `token-admin` identity for you (`soroban config identity create token-admin`) and deploy a Fungible Token contract as well as the [crowdfund contract](./contracts/crowdfund), with this account as admin.
3939

4040
2. Select the Futurenet network in your Freighter browser extension
4141

@@ -91,7 +91,7 @@ You have three options: 1. Deploy on [Futurenet](https://soroban.stellar.org/doc
9191

9292
You can use your own local soroban-cli:
9393

94-
./initialize.sh standalone
94+
NETWORK=standalone npm run setup
9595

9696
Or run it inside the soroban-preview docker container:
9797

@@ -148,14 +148,3 @@ Then via the web UI, users should be able to:
148148
- Deposit an allowed asset
149149
- See their deposit(s) appear on the page as the transactions are confirmed.
150150
- "Live"-Update the page with the total amount with the new amount
151-
152-
Wallet Integration & Data Fetching
153-
==================================
154-
155-
There is a `./wallet` directory, which contains a small library to connect to
156-
the user's freighter wallet, as well as some React hooks to talk to a
157-
soroban-rpc server (e.g. `soroban-cli serve`), to fetch data and send
158-
transactions.
159-
160-
Data from contracts is fetched using the `useContractValue` hook from @soroban-react/contracts. Transactions are submitted to the network
161-
using the `useSendTransaction` from @soroban-react/contracts.

components/ProviderExample.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

components/atoms/connect-button/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { useSorobanReact } from '@soroban-react/core'
2+
import { setAllowed } from '@stellar/freighter-api'
33
import styles from './style.module.css'
44

55
export interface ConnectButtonProps {
@@ -8,16 +8,11 @@ export interface ConnectButtonProps {
88
}
99

1010
export function ConnectButton({ label, isHigher }: ConnectButtonProps) {
11-
const { connect } = useSorobanReact()
12-
const openConnectModal = async () => {
13-
await connect()
14-
}
15-
1611
return (
1712
<button
1813
className={styles.button}
1914
style={{ height: isHigher ? 50 : 38 }}
20-
onClick={openConnectModal}
15+
onClick={setAllowed}
2116
>
2217
{label}
2318
</button>

0 commit comments

Comments
 (0)