Skip to content

Commit e4c07c9

Browse files
Austin BaggioAustin Baggio
authored andcommitted
Updated getting started with some more explicit instructions and addressed language inconsistencies
1 parent 3d91c13 commit e4c07c9

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

docs/develop/contracts/js/quickstart.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
---
22
id: enclave-quickstart
3-
title: Javascript Enclave
3+
title: JavaScript Enclave
44
sidebar_label: Enclave Quickstart
55
---
66

7-
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.
7+
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 docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript) for more details.
1010

1111
<blockquote class="warning">
12-
<strong>heads up</strong><br /><br />
13-
14-
Javascript smart contract development is not recommended for financial use cases as it is still very new to the NEAR ecosystem.
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.
1513

1614
</blockquote>
1715

1816
## Overview {#overview}
1917

20-
The Javascript Enclave, or jsvm for short, provides an isolated environment where users can learn the basics of how to write smart contracts on NEAR. This isolated environment is run on a virtual machine, similar to how [aurora](https://doc.aurora.dev/getting-started/aurora-engine) operates. Standard smart contracts that are built using Rust or AssemblyScript compile to [WebAssembly](https://webassembly.org/) or simply WASM. With the jsvm, contracts are encoded to base64 and are deployed to a virtual machine.
18+
The JavaScript Enclave, or JavaScript Virtual Machine (jsvm) provides an isolated environment where users can learn the basics of how to write smart contracts on NEAR. This isolated environment is run on a virtual machine, similar to how [Aurora](https://doc.aurora.dev/getting-started/aurora-engine) operates. Standard smart contracts that are built using Rust or AssemblyScript compile to [WebAssembly](https://webassembly.org/) or simply WASM. With the jsvm, contracts are encoded to base64 and are deployed to a virtual machine.
2119

2220
There are several pros and cons when comparing the enclave approach to the regular WASM approach. The key differences are outlined below.
2321

2422
| Areas | WebAssembly | Enclave |
2523
|---------------------------|--------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2624
| Can interact with any smart contract on NEAR |||
2725
| Synchronous Cross-Contract Calls |||
28-
| Standards Support |||
29-
| Function Call Access Key Support |||
26+
| Standards Support ||Not in V1.0|
27+
| Function Call Access Key Support ||Not in V1.0|
3028

31-
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.
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.
3230

3331
## Quickstart {#quickstart}
3432

35-
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.
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.
3634

3735
### Prerequisites
3836

@@ -57,7 +55,7 @@ npm install -g near-cli
5755

5856
### Creating a project
5957

60-
Now that you have Node and npm installed, create a new directory to initialize the project in.
58+
Now that you have Node, npm, and the NEAR-CLI installed, create a new directory to initialize the project in.
6159

6260
```bash
6361
mkdir javascript-enclave-quickstart && cd javascript-enclave-quickstart
@@ -157,20 +155,20 @@ javascript-enclave-quickstart
157155

158156
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.
159157

160-
The contract presents 2 methods: set_greeting and get_greeting. The first one stores a String in the contract's parameter message, while the second one retrieves it. By default, the contract returns the message "Hello".
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".
161159

162160
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:
163161

164162
```js
165163
import {NearContract, NearBindgen, call, view, near} from 'near-sdk-js'
166164
```
167165
Let's break down these imports to help you understand why they're necessary.
168-
- `NearContract`: allows our contract to inherit important functionalities for changing and reading the contract's state.
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.
169167
- `NearBindgen`: allows your contract to compile down to something that is NEAR compatible.
170-
- `call, view`: allows your methods to be view functions or change functions.
168+
- `call, view`: allows your methods to be view only functions or mutable (change) functions.
171169
- `near`: allows you to access important information within your functions such as the signer, predecessor, attached deposit etc..
172170

173-
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:
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:
174172

175173
```js
176174
// Define the default message
@@ -243,6 +241,8 @@ class StatusMessage extends NearContract {
243241
}
244242
}
245243
```
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.
245+
246246

247247
### Building
248248

@@ -271,7 +271,15 @@ near js deploy --accountId <YOUR_ACCOUNT_ID> --base64File build/contract.base64
271271
272272
### Interacting
273273

274-
Now that your contract is deployed, you can start interacting with it. The first thing to do is initialize the contract. For simplicity, export the account ID that the contract is deployed to into an environment variable.
274+
The return from the deploy should include an account address in the first line after Account id:
275+
276+
```bash
277+
Starting deployment. Account id: <someAccountID>, node: https://rpc.testnet.near.org, helper: https://helper.testnet.near.org, file: build/contract.base64, JSVM: jsvm.testnet
278+
Transaction Id EvSt3A4auSkBWKUvRo2JtbP7UdwimLmRh7fyn89RZ1d4
279+
To see the transaction in the transaction explorer, please open this url in your browser
280+
https://explorer.testnet.near.org/transactions/EvSt3A4auSkBWKUvRo2JtbP7UdwimLmRh7fyn89RZ1d4
281+
```
282+
Now that your contract is deployed, you can start interacting with it. The first thing to do is initialize the contract. For simplicity, export the account ID that the contract is deployed to into an environment variable.
275283

276284
```bash
277285
export JS_CONTRACT="dev-1653584404106-63749024395789"

0 commit comments

Comments
 (0)