You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/for_developers/smart_contracts/getting_started.md
+57-26Lines changed: 57 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,13 @@ tags:
9
9
Before we dive deep into the structure of a contract and the SDK's semantics, we require some background information about the semantics enforced by ParallelChain Mainnet. The full capabilities of ParallelChain Mainnet continue to grow with active developers
10
10
and a growing community. Let's see how smart contracts are called and processed by a node in the form of transactions.
11
11
12
-
First, the ParallelChain Client (`pchain_client`) will submit a transaction when making a smart contract call to the validating node using a serialization crate [pchain-types](https://github.com/parallelchain-io/pchain-types-rust). The node's RPC service and mempool will process the list of transactions and check for validity and correctness.
12
+
First, the ParallelChain Client (`pchain_client`) will submit a transaction when making a smart contract call to the validating node using a serialization crate [pchain-types](https://crates.io/crates/pchain-types). The node's RPC service and mempool will process the list of transactions and check for validity and correctness.
13
13
14
-
Transactions that fail the validation check may not be included in a block. The transactions are then packed in a block and sent to the execution engine in the node to execute the transactions.
14
+
[Transactions](../../fundamentals/transactions.md#how-transaction-works) that fail the validation check may not be included in a [block](../../fundamentals/blocks.md#how-block-works). The transactions are then packed in a block and sent to the execution engine in the node to execute the transactions.
15
15
16
-
The executor will call `wasmer` (Web Assembly Engine) which provides an isolated context to perform the execution. This enables the smart contract code to read the current state of the blockchain and interact with it. However, the execution results are temporarily stored and subject to further checks before the block may be committed or rolled back on error.
16
+
The executor will call [wasmer](https://crates.io/crates/wasmer) (Web Assembly Engine) which provides an isolated context to perform the execution. This enables the smart contract code to read the current state of the blockchain and interact with it. However, the execution results are temporarily stored and subject to further checks before the block may be committed or rolled back on error.
17
17
18
-
`wasmer` also computes the gas fees through a metering module, which is responsible for limiting the execution to the amount of gas paid. Each transaction returns a result in the form of receipts along with logs. The receipts (with or without log), transactions and block itself will contain its hash (or Merkle proof) and will be all included in the same block.
18
+
`wasmer` also computes the [gas](../../fundamentals/gas.md) fees through a metering module, which is responsible for limiting the execution to the amount of gas paid. Each transaction returns a result in the form of receipts along with logs. The receipts (with or without log), transactions and block itself will contain its hash (or Merkle proof) and will be all included in the same block.
19
19
20
20
21
21
## Smart Contract Development Kit
@@ -36,20 +36,52 @@ For more information on Rust's crate system, see [Rust Book Chapter 7: Packages
36
36
Please specify the dependency in `Cargo.toml` for using SDK by fetching from [crates.io](https://crates.io/) or repository in Github.
The details about the macros (e.g. `contract`, `contract_methods`, `call`) used in the code can be found in later sections [Contract Methods](./advanced/contract_methods.md) and [Contract Storage](./advanced/contract_storage.md). Let's skip knowing them first, and continue reading about building and deploying the contract in following sections.
51
81
52
-
**pchain_compile** is a CLI build tool for smart contract developers to build their source code to WASM binaries for deployment on
82
+
## Building The Contract With `pchain_compile`
83
+
84
+
[pchain_compile](https://github.com/parallelchain-io/pchain-compile) is a CLI build tool for smart contract developers to build their source code to WASM binaries for deployment on
53
85
ParallelChain Mainnet.
54
86
55
87
The WASM binary generated from a generic cargo build process has the following disadvantages:
@@ -63,10 +95,10 @@ The WASM binary generated from a generic cargo build process has the following d
63
95
64
96
- Executing the build process in a docker environment with pre-defined toolchain versioning.
65
97
66
-
- Optimizing and compressing the size of the WASM binary with the help of `wasm-snip` and `wasm-opt` packages.
98
+
- Optimizing and compressing the size of the WASM binary with the help of [wasm-snip](https://crates.io/crates/wasm-snip) and [wasm-opt](https://crates.io/crates/wasm-opt) packages.
67
99
68
100
69
-
### Downloading**pchain_compile**
101
+
### Download**pchain_compile**
70
102
71
103
`pchain_compile` supports Linux, macOS and Windows. Depending on the operating system, they can be downloaded from Assets of ParallelChain Lab's Git Hub [release page](https://github.com/parallelchain-io/pchain-compile/releases).
72
104
@@ -80,7 +112,7 @@ cargo install pchain_compile
80
112
81
113
82
114
83
-
### Building WASM Binary
115
+
### Build WASM Binary
84
116
85
117
In order to build a `WASM` binary of the smart contract, run the following command:
86
118
@@ -103,7 +135,7 @@ A `.wasm` file will be generated in the current directory.
103
135
104
136
## Deploying a Smart Contract
105
137
106
-
You can deploy the contract using the pchain_client command line tool. You should make sure to obtain your latest account nonce before submitting the transaction.
138
+
You can deploy the contract using the pchain_client command line tool. You should make sure to [know your latest account nonce](../../for_users/pchain_client_cli/query.md#check-account-related-information) before submitting the transaction.
107
139
108
140
=== "Linux / macOS"
109
141
```bash
@@ -130,7 +162,7 @@ You can deploy the contract using the pchain_client command line tool. You shoul
130
162
131
163
You can follow the instruction in [Create Transaction](../../for_users/pchain_client_cli/transaction.md) about submiting a transaction through `pchain-client`.
132
164
133
-
## Checking Contract in State
165
+
## Checking Contract In State
134
166
135
167
To verify that the smart contract is deployed correctly, you can run the command `query` with the flag `contract`. It queries the state of the blockchain and saves the wasm code as `code.wasm` in the current directory.
136
168
If you want to store the contract file in your preferred location, you need to provide the flag `destination` to specify the path with your preferred file extension:
@@ -146,20 +178,15 @@ If you want to store the contract file in your preferred location, you need to p
146
178
147
179
## Calling Contract
148
180
149
-
Suppose you have already deployed a contract that contains a `call` method as follows:
181
+
Suppose you have already deployed a contract that contains a `call` method named `hello_from`as mentioned in previous section [Implement Smart Contract](#implement-smart-contract):
To invoke this contract in the blockchain by using `pchain_client`, you can prepare a JSON file that contains a list of arguments and matches with the `call` method. For example, this `call` method takes a string argument. Then, the content of the JSON file should be as follows:
189
+
Toinvokethiscontractbyusing `pchain_client`, youcanprepareaJSONfilethatcontainsalistofargumentsandmatcheswiththe `call` method.Forexample, this `call` methodtakesastringargument.Then, thecontentoftheJSONfileshouldbeasfollows:
163
190
164
191
```json
165
192
{
@@ -169,9 +196,9 @@ To invoke this contract in the blockchain by using `pchain_client`, you can prep
169
196
}
170
197
```
171
198
172
-
This JSON file will be used in the subcommand `call` as mentioned in the subsequent sections on this page.
199
+
This JSON file will be used in creating a transaction with [Call Command](../../fundamentals/transactions.md#account-commands).
173
200
174
-
### Submitting Transaction with Call Command
201
+
### Submit Transaction With Call Command
175
202
176
203
To call a smart contract, submit a transaction with your account nonce and contract address using the `pchain_client`.
177
204
@@ -204,6 +231,10 @@ Here is the command to call a contract:
204
231
--amount <AMOUNT_TO_CONTRACT>
205
232
```
206
233
234
+
The command argument `method` is the name of the method with macro `#[call]` in the code. Take the contract in [Implement Smart Contract](#implement-smart-contract) as example, "hello_from" should be set as the value of the command argument `method`.
235
+
236
+
The command argument `arguments` is the JSON file that contains the method arguments to the method being called in the contract. The way to create this JSON file is described in previous section [Calling Contract](#calling-contract).
237
+
207
238
The gas limit required for the transaction depends on the complexity of the smart contract. For safety reasons, you can always set a higher gas limit. You can also test contract calls on testnet to reassure.
208
239
209
240
You can follow the instruction in [Create Transaction](../../for_users/pchain_client_cli/transaction.md) about submiting a transaction through `pchain-client`.
@@ -221,7 +252,7 @@ To query the resulting receipt of the transaction,
221
252
222
253
The commands stored in `transaction` and command receipts in `receipt` are following the same order. That means you can always find the corresponding transaction from a command receipt.
223
254
224
-
### Parsing Call Result
255
+
### Parse Call Result
225
256
226
257
To parse the response from the contract method, represented in the field named `return value` , which is in `CallResult` format, you can use the `parse call-result` command in ParallelChain Client.
Copy file name to clipboardExpand all lines: docs/for_developers/smart_contracts/installing_sdk.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,15 +7,15 @@ tags:
7
7
8
8
## Installing Rust
9
9
10
-
To install the required toolkits, the standard method is by `rustup`, which maintains dependencies and is a version manager for `cargo` and `rustc` (the rust compiler). Detailed installation instructions can be found on the [official website](https://www.rust-lang.org/tools/install)
10
+
To install the required toolkits, the standard method is by `rustup`, which maintains dependencies and is a version manager for `cargo` and `rustc` (the rust compiler). Detailed installation instructions can be found on the [official website](https://www.rust-lang.org/tools/install).
11
11
12
12
## Setting up a Development Environment
13
13
14
14
A recommended Integrated Development Environment (IDE) is [VSCode](https://code.visualstudio.com/), which allows the addition of the plugin [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer) to type-check all of your code on save. This feature allows you to locate errors in the code easily, and the error messages displayed in the IDE are the same as when executing the `cargo build` command. However, any other editor that is comfortable for you can be used. However, any other editor that is comfortable for you can be used.
15
15
16
16
## Installing Wasm Toolchain (Optional)
17
17
18
-
ParallelChain Mainnet also provides a smart contract compilation tool called `pchain-compile` to compile your Rust smart contract into WASM bytecode. While not necessary, the Installation of Wasm Toolchain can help check if your code is compilable before using the time-consuming process in the use of `pchain-compile`.
18
+
ParallelChain Mainnet also provides a smart contract compilation tool called [pchain-compile](getting_started.md#building-the-contract-with-pchain_compile) to compile your Rust smart contract into WASM bytecode. While not necessary, the Installation of Wasm Toolchain can help check if your code is compilable before using the time-consuming process in the use of `pchain-compile`.
19
19
20
20
The `wasm32-unknown-unknown` toolchain is required for smart contracts to compile as WASM. To add the wasm toolchain in Rust, type the command below:
0 commit comments