-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update cli command in getting started guide and closes #1138 #1162
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,16 +19,13 @@ Let's get started. | |
|
||
You're going to need [Node.js](https://nodejs.org/en/download/package-manager/) v18.14.1 or greater. If you haven't yet, install it now. | ||
|
||
We want to initialize our current project as an Astro project. To do this, we can again turn to the `stellar contract init` command, which has a `--frontend-template` flag that allows us to pass the url of a frontend template repository. As we learned in [Storing Data](../smart-contracts/getting-started/storing-data.mdx#adding-the-increment-contract), `stellar contract init` will not overwrite existing files, and is safe to use to add to an existing project. | ||
|
||
From our `soroban-hello-world` directory, run the following command to add the Astro template files. | ||
We want to initialize our current project as an Astro project. From our `soroban-hello-world` directory, run the following command to add the Astro template files. | ||
|
||
```sh | ||
stellar contract init ./ \ | ||
--frontend-template https://github.com/stellar/soroban-astro-template | ||
git clone [email protected]:stellar/soroban-template-astro.git | ||
``` | ||
|
||
This will add the following to your project, which we'll go over in more detail below. | ||
This will clone the following to your project, which we'll go over in more detail below. | ||
|
||
```bash | ||
├── CONTRIBUTING.md | ||
|
@@ -495,4 +492,4 @@ At this point, you've seen a full end-to-end example of building a contract on S | |
|
||
- See more complex example contracts in the [Example Contracts](../smart-contracts/example-contracts/README.mdx) section. | ||
- Learn more about the [internal architecture and design](../../learn/encyclopedia/contract-development/README.mdx) of Soroban. | ||
- Learn how to find other templates for use with `--frontend-template`, other than [stellar/soroban-template-astro](https://github.com/stellar/soroban-astro-template), and how to build your own: [Develop contract initialization frontend templates](../guides/dapps/soroban-contract-init-template.mdx) | ||
- Learn how to find other templates other than [stellar/soroban-template-astro](https://github.com/stellar/soroban-astro-template), and how to build your own: [Develop contract initialization frontend templates](../guides/dapps/soroban-contract-init-template.mdx) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,22 +1,22 @@ | ||||||
--- | ||||||
title: Develop contract initialization frontend templates | ||||||
title: Develop contract with frontend templates | ||||||
description: Understand, find, and create your own frontend templates for use with Stellar CLI's `stellar contract init` command | ||||||
--- | ||||||
|
||||||
<head> | ||||||
<title>Develop contract initialization frontend templates</title> | ||||||
<title>Develop contract witn frontend templates</title> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<meta charSet="utf-8" /> | ||||||
<meta | ||||||
property="og:title" | ||||||
content="Develop contract initialization frontend templates" | ||||||
content="Develop contract with frontend templates" | ||||||
/> | ||||||
<meta | ||||||
property="og:description" | ||||||
content="Understand, find, and create your own frontend templates for use with Stellar CLI's `stellar contract init` command" | ||||||
/> | ||||||
</head> | ||||||
|
||||||
This guide picks up where [Build a Dapp Frontend](../../apps/dapp-frontend.mdx) left off, taking a deeper look at the `--frontend-template` used there. From there, we'll: | ||||||
This guide picks up where [Build a Dapp Frontend](../../apps/dapp-frontend.mdx) left off. From there, we'll: | ||||||
|
||||||
1. Search GitHub for other Soroban templates | ||||||
1. Build our own simple template | ||||||
|
@@ -29,11 +29,11 @@ The official template maintained by Stellar Development Foundation (SDF), as use | |||||
|
||||||
(You may wonder why it makes this unpopular choice. A fair question! The team wanted to balance actual utility with broad approachability. Not everyone learning Stellar and Soroban is familiar with React, or any other UI library. It also demonstrates that core Soroban libraries all work with any JavaScript project.) | ||||||
|
||||||
But note that the CLI's `contract init` command was made to work with _any_ frontend template. It need not even live on GitHub! Simply pass another valid git URL to the command, and it will clone that instead of the official repository: | ||||||
But note that the CLI's `contract init` command was made to work with a specific set of templates. To use other templates, we will clone other templates from repository: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change just removes the |
||||||
|
||||||
```bash | ||||||
# the following is NOT a valid git repository, and will not work 😄 | ||||||
stellar contract init my-new-project --frontend-template https://whatever.cool/project/you/want | ||||||
git clone https://whatever.cool/project/you/want | ||||||
``` | ||||||
|
||||||
So how can you find other valid frontend templates? | ||||||
|
@@ -54,9 +54,7 @@ This will be easier than you might imagine. There are a few gotchas, but overall | |||||
|
||||||
### But first, how are these projects organized? | ||||||
|
||||||
When you run `stellar contract init`, it _always_ includes a Rust/Cargo project, with a `Cargo.toml` that defines a workspace, and workspace members located in a `contracts` folder. At a minimum, there's one contract, `contracts/hello_world`, but you can get more by using `--with-example`. | ||||||
|
||||||
Separately, you _may_ include a `--frontend-template`. Frontend templates so far have all been Node projects, which have a `package.json` in the root. In the final composite project, the Node project and Rust project live side-by-side, and the frontend template expects the Rust project to be there. It expects a `contracts` folder with one or more subfolders, and it expects a `target` directory with all the Rust build artifacts. | ||||||
When you run `stellar contract init`, it _always_ includes a Rust/Cargo project, with a `Cargo.toml` that defines a workspace, and workspace members located in a `contracts` folder. At a minimum, there's one contract, `contracts/hello_world`, but you can get more by using `--name`. | ||||||
|
||||||
So keep that in mind. We're making a fairly simple Node project, and telling it about our Soroban stuff, like the `contracts` folder. | ||||||
|
||||||
|
@@ -99,7 +97,7 @@ So this script: | |||||
4. _binds_ contracts — that is, it creates NPM projects for each deployed contract by running `stellar contract bindings typescript` | ||||||
5. imports the contracts for straightforward use in the rest of your project | ||||||
|
||||||
Remember that it needs to do this all _in a contract-agnostic way_. That is, the `--frontend-template` choice is separate from the `--with-example` choice. The frontend template doesn't know what contracts it might find! But it needs to build, deploy, bind, and import whatever's there. | ||||||
Remember that it needs to do this all _in a contract-agnostic way_. The frontend template doesn't know what contracts it might find! But it needs to build, deploy, bind, and import whatever's there. | ||||||
|
||||||
So this script does that. | ||||||
|
||||||
|
@@ -215,7 +213,7 @@ stellar network container start local | |||||
Now we can run `contract init`. Let's include one extra contract. Then we'll run the `dev` script (which, remember, will run the `initialize.js` script first): | ||||||
|
||||||
```bash | ||||||
stellar contract init . --with-example increment | ||||||
stellar contract init . --name increment | ||||||
npm run dev | ||||||
``` | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,12 +27,12 @@ This tutorial assumes that you've already completed the previous steps in Gettin | |
|
||
## Adding the increment contract | ||
|
||
The `stellar contract init` command allows us to initialize a new project with any of the example contracts from the [soroban-examples](https://github.com/stellar/soroban-examples) repo, using the `--with-example` (or `-w`) flag. | ||
The `stellar contract init` command allows us to initialize a new project with any of the example contracts from the [soroban-examples](https://github.com/stellar/soroban-examples) repo, using the `--name` flag, to specify a new contract's name. | ||
|
||
It will not overwrite existing files, so we can also use this command to add a new contract to an existing project. Run the command again with a `--with-example` flag to add an `increment` contract to our project. From inside our `soroban-hello-world` directory, run: | ||
It will not overwrite existing files unless we explicily pass in `--ovewrite` flag. Run the command with a `--name` flag to add an `increment` contract to our project. From inside our `soroban-hello-world` directory, run: | ||
|
||
```sh | ||
stellar contract init ./ --with-example increment | ||
stellar contract init . --name increment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment this command copies the contents of the
The deprecation notice about
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another idea would be to use |
||
``` | ||
|
||
This will create a new `contracts/increment` directory with the following files: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will clone the template repo's files into a new
soroban-template-astro
directory, insidesoroban-hello-world
. in order to use these template files, i think we'd need to instruct the user to copy them into the root of thesoroban-hello-world
project.