Skip to content

Commit 66c7ee9

Browse files
authored
Apply suggestions from code review
1 parent 08c1d2e commit 66c7ee9

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

docs/develop/contracts/js/quickstart.md

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ sidebar_label: Enclave Quickstart
66

77
The NEAR platform has historically supported writing contracts in Rust and AssemblyScript. This document aims to introduce developers to a new way of writing smart contracts by using JavaScript.
88

9-
JavaScript is a widely used programming language that is most well known for its Webpage scripting usages. See the [official JavaScript docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript) for more details.
9+
JavaScript is a widely-used programming language that is most well known for its Webpage scripting usages. See the [official JavaScript documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript) for more details.
1010

11-
<blockquote class="warning">
12-
<strong>Heads up:</strong> JavaScript smart contract development is not recommended for financial use cases as it is still very new to the NEAR ecosystem.
13-
14-
</blockquote>
11+
:::warning Heads up
12+
JavaScript smart contract development is not recommended for financial use cases as it is still very new to the NEAR ecosystem.
13+
:::
1514

1615
## Overview {#overview}
1716

@@ -23,14 +22,14 @@ There are several pros and cons when comparing the enclave approach to the regul
2322
|---------------------------|--------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2423
| Can interact with any smart contract on NEAR |||
2524
| Synchronous Cross-Contract Calls |||
26-
| Standards Support ||Not in V1.0|
27-
| Function Call Access Key Support ||Not in V1.0|
25+
| Standards Support ||Not in v1.0|
26+
| Function Call Access Key Support ||Not in v1.0|
2827

29-
The JavaScript Enclave is a very powerful tool to help you kickstart your smart contract programming journey. Writing contracts in javascript is much easier than learning Rust and the ability for cross-contract calls to be synchronous can greatly help with people's understanding of how contracts can work.
28+
The JavaScript Enclave is a very powerful tool to help you kickstart your smart contract programming journey. Writing contracts in JavaScript is much easier than learning Rust, and thanks to the jsvm's ability to handle cross-contract calls synchronously can greatly help with people's understanding of how contracts can work.
3029

3130
## Quickstart {#quickstart}
3231

33-
In this quickstart guide, you'll learn the basics of setting up a new JavaScript smart contract on the enclave that stores and retrieves a greeting message. You'll then go through and create a simple web-based frontend that displays the greeting and allows you to change it.
32+
In this quick-start guide, you'll learn the basics of setting up a new JavaScript smart contract on the enclave that stores and retrieves a greeting message. You'll then create a simple web-based frontend that displays the greeting and allows you to change it.
3433

3534
### Prerequisites
3635

@@ -47,7 +46,7 @@ node -v
4746
npm -v
4847
```
4948

50-
It's important to have the **newest** version of the NEAR-CLI installed such that you can make use of the javascript features. To install or update, run:
49+
It's important to have the **newest** version of the [NEAR-CLI](https://docs.near.org/docs/tools/near-cli) installed such that you can make use of the JavaScript features. To install or update, run:
5150

5251
```
5352
npm install -g near-cli
@@ -113,13 +112,13 @@ Once the package has successfully been installed, you can create a convenient sc
113112

114113
> **Note:** This is optional and you can simply run `near-sdk build` instead.
115114
116-
You'll now want to create the `src` directory and initialize a new javascript file `index.js` where your contract logic will live.
115+
You'll now want to create the `src` directory and initialize a new JS file `index.js` where your contract logic will live.
117116

118117
```bash
119118
mkdir src && cd src && touch index.js && cd ..
120119
```
121120

122-
The last step is to create a new file called `babel.config.json` which allows you to configure how the contract is built. In the project root, create a new file and add the following content.
121+
The last step is to create a new file called `babel.config.json` which allows you to configure how the contract is built. In the project's root folder, create a new file and add the following content.
123122

124123
```bash
125124
touch babel.config.json
@@ -155,20 +154,26 @@ javascript-enclave-quickstart
155154

156155
Now that you have the basic structure outlined for your project, it's time to start writing your first contract. You'll create a simple contract for setting and getting a greeting message on-chain.
157156

158-
The contract presents 2 methods: ```set_greeting``` and ```get_greeting```. ```set_greeting```stores a String in the contract's parameter message, while ```get_greeting``` retrieves it. By default, the contract returns the message "Hello".
157+
The contract presents 2 methods: `set_greeting` and `get_greeting`:
158+
- `set_greeting` stores a String in the contract's parameter message,
159+
- while `get_greeting` retrieves it.
160+
161+
By default, the contract returns the message "Hello".
159162

160163
Start by opening the `src/index.js` file as this is where your logic will go. You'll then want to add some imports that will help when writing the contract:
161164

162165
```js
163166
import {NearContract, NearBindgen, call, view, near} from 'near-sdk-js'
164167
```
168+
165169
Let's break down these imports to help you understand why they're necessary.
166-
- `NearContract`: allows our contract to inherit functionalities for changing and reading the contract's state. State can be thought of as the data stored on chain.
170+
171+
- `NearContract`: allows the contract to inherit functionalities for changing and reading the contract's state. The state can be thought of as the data stored on-chain.
167172
- `NearBindgen`: allows your contract to compile down to something that is NEAR compatible.
168-
- `call, view`: allows your methods to be view only functions or mutable (change) functions.
169-
- `near`: allows you to access important information within your functions such as the signer, predecessor, attached deposit etc..
173+
- `call`, `view`: allows your methods to be view-only functions or mutable (change) functions.
174+
- `near`: allows you to access important information within your functions such as the signer, predecessor, attached deposit, etc.
170175

171-
Now that you've imported everything from the sdk, create a new class that extends the `NearContract`. This class will contain the core logic of your smart contract. You can also use this opportunity to create a default message variable. Below the import add:
176+
Now that you've imported everything from the SDK, create a new class that extends the `NearContract`. This class will contain the core logic of your smart contract. You can also use this opportunity to create a default message variable. Below the `import` add:
172177

173178
```js
174179
// Define the default message
@@ -185,7 +190,7 @@ class StatusMessage extends NearContract {
185190
}
186191
}
187192
```
188-
Running the constructor will default the contract's `message` state variable with the `DEFAULT_MESSAGE`. There's no way to get the current greeting, however. Within the class, add the following function.
193+
Running the constructor will default the contract's `message` state variable with the `DEFAULT_MESSAGE`. Since there's no way to get the current greeting, within the class you can add the following `view` function:
189194

190195
```js
191196
// Public method - returns the greeting saved, defaulting to DEFAULT_MESSAGE
@@ -241,12 +246,14 @@ class StatusMessage extends NearContract {
241246
}
242247
}
243248
```
244-
> <strong>Heads up:</strong> You might see a warning from your JavaScript linter because the NEAR SDK uses an custom decorators which is experimentatl feature. This will be addressed in a future release of the JS SDK. It can be ignored for now.
249+
:::note Heads up
250+
You might see a warning from your JavaScript linter because the NEAR SDK uses a custom decorator which is an experimental feature. This will be addressed in a future release of the JS SDK. It can be ignored for now.
251+
:::
245252

246253

247254
### Building
248255

249-
Now that your contract is finished, it's time to build and deploy it. Run the following command to build your JS code and get the `build/contact.base64` contract file.
256+
Now that your contract is finished, it's time to build and deploy it. Run the following command to build your JS code and get the `build/contract.base64` contract file.
250257

251258
```
252259
yarn build
@@ -284,13 +291,13 @@ Now that your contract is deployed, you can start interacting with it. The first
284291
```bash
285292
export JS_CONTRACT="dev-1653584404106-63749024395789"
286293
```
287-
You'll now initialize the contract such that the default greeting is set. If you try to interact with the contract before it's initialized, you'll be thrown an error saying "Contract state is empty".
294+
You'll now initialize the contract such that the default greeting is set. If you try to interact with the contract before it's initialized, you'll get an error saying "Contract state is empty".
288295

289296
```bash
290297
near js call $JS_CONTRACT init --accountId $JS_CONTRACT --deposit 0.1
291298
```
292299

293-
Once the contract is initialized, you can view the current greeting by performing a view call:
300+
Once the contract is initialized, you can view the current greeting by performing a `view` call:
294301

295302
```bash
296303
near js view $JS_CONTRACT get_greeting

0 commit comments

Comments
 (0)