- Notifications
You must be signed in to change notification settings - Fork 220
Update Dapp Frontend Guide #1941
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
base: main
Are you sure you want to change the base?
Conversation
| Preview is available here: |
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.
looking really good! left some questions, thoughts, and plenty of nitpicks lol!
| # Develop a Contract with Frontend Templates | ||
| | ||
| This is a continuation of the [Getting Started tutorial](../smart-contracts/getting-started/README.mdx), where you should have deployed two smart contracts to the public network. In this section, we'll create a web app that interacts with the contracts via RPC calls. | ||
| This guide picks up where [Build a Dapp Frontend](https://developers.stellar.org/docs/build/apps/dapp-frontend) left off. From there, we'll: |
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 link will probably need to be updated to remove the domain name, but it's also a link to this page. not sure where we want to point to, but should double-check.
| ## Search GitHub for other Soroban templates | ||
| | ||
| If you're new to frontend, don't worry. We won't go too deep. But it will be useful for you to see and experience the frontend development process used by Soroban apps. We'll cover the relevant bits of JavaScript and Astro, but teaching all of frontend development and Astro is beyond the scope of this tutorial. | ||
| The official template maintained by Stellar Development Foundation (SDF), as used in [Build a Dapp Frontend](https://developers.stellar.org/docs/build/apps/dapp-frontend), lives on GitHub at [stellar/soroban-template-astro](https://github.com/stellar/soroban-astro-template). It uses the [Astro web framework](https://astro.build/). While Astro works with React, Vue, Svelte, and any other UI library, the template opts not to use them, preferring Astro's own templating language, which uses vanilla JavaScript with no UI library. |
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.
same as above with the link.
also, that astro template got archived, so i'm not sure if we want to point it out to others?
| ## Make your own template | ||
| | ||
| This project is set up as an NPM Workspace, and so the `hello_world` client library was generated in the `packages` directory at `packages/hello_world`. | ||
| Let’s make our own template! In this example template, we use SolidJS as the JavaScript framework, but other frameworks can be used with minor modifications. The template is using the `hello world` example smart contract, and is a part of the template initialization; bindings for the `hello world` smart contract are created. |
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.
| Let’s make our own template! In this example template, we use SolidJS as the JavaScript framework, but other frameworks can be used with minor modifications. The template is using the `hello world` example smart contract, and is a part of the template initialization; bindings for the `hello world` smart contract are created. | |
| Let’s make our own template! In this example template, we use SolidJS as the JavaScript framework, but other frameworks can be used with minor modifications. The template is using the `hello_world` example smart contract. As a part of the template initialization, bindings for the `hello_world` smart contract are created. |
| ```bash | ||
| | ||
| In addition to generating the NPM packages, `initialize.js` will also: | ||
| npx degit solidjs/templates/ts soroban-template-solid |
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.
might be nice to add a # bash comment pointing to where the instructions for command this came from (i'm assuming the solid docs somewhere?)
| | ||
| Let's take a look at the contents of the `.env` file: | ||
| npm install dotenv glob util | ||
| |
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.
I think you might have some extra line-breaks surrounding some of the bash code blocks. make sure there are no blank lines between the three backticks on either side of the code
| Now that the smart contract has been built, we can deploy the smart contract to the network, so we can invoke the smart contract functions from any client, such as our SolidJS template. | ||
| While `hello` is a simple view-only/read method, `increment` changes on-chain state. This means that someone needs to sign the transaction. So we'll need to add transaction-signing capabilities to the frontend. | ||
| There are three functions related to contract deployment. One that uses the Stellar CLI to deploy the wasm to the network (`deploy()`), one that calls the deploy function for each wasm found (`deployAll()`), in case there is more than one smart contract, and finally a helper function that gets the contract name by parsing the wasm file name. |
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.
| There are three functions related to contract deployment. One that uses the Stellar CLI to deploy the wasm to the network (`deploy()`), one that calls the deploy function for each wasm found (`deployAll()`), in case there is more than one smart contract, and finally a helper function that gets the contract name by parsing the wasm file name. | |
| There are three functions related to contract deployment. One that uses the Stellar CLI to deploy the Wasm to the network (`deploy()`), one that calls the deploy function for each Wasm found (`deployAll()`), in case there is more than one smart contract, and finally a helper function that gets the contract name by parsing the Wasm file name. |
| `stellar contract bindings typescript --contract-id ${contractid} --output-dir ${dirname}/packages/${alias} --overwrite`, | ||
| ); | ||
| // Build the package | ||
| execSync(`(cd ${dirname}/packages/${alias} && npm i && npm run build)`); |
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.
might wanna add && cd ${dirname} or something similar to the end of this command?
| ``` | ||
| With the package installed, we are going to create a new simple file where our instantiated kit and simple state will be located. Create the file `src/stellar-wallets-kit.ts` and paste this: | ||
| The `bindAll()` function iterates the `smartContracts[]` array. The reason for not just using the array of wasms, like in the `deployAll()` function, is that we need the contract ID to generate the bindings. |
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.
| The `bindAll()` function iterates the `smartContracts[]` array. The reason for not just using the array of wasms, like in the `deployAll()` function, is that we need the contract ID to generate the bindings. | |
| The `bindAll()` function iterates the `smartContracts[]` array. The reason for not just using the array of wasms, like in the `deployAll()` function, is that we need the contract ID to invoke the generated bindings functions on the network. |
you can actually generate bindings from a Wasm file, but this will leave you with a client instance that requires you to specify a address
| `import * as Client from '${alias}';\n` + | ||
| `export default new Client.Client({\n` + |
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.
| `import * as Client from '${alias}';\n` + | |
| `export default new Client.Client({\n` + | |
| `import { Client } from '${alias}';\n` + | |
| `export default new Client({\n` + |
| ```javascript | ||
| | ||
| import type { Component } from 'solid-js'; |
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.
| ```javascript | |
| import type { Component } from 'solid-js'; | |
| ```javascript | |
| import type { Component } from 'solid-js'; |
some more blank lines
https://developers-pr1941.previews.kube001.services.stellar-ops.com/docs/build/apps/dapp-frontend