Skip to content

Commit ed247ff

Browse files
chore(docs): revision election dApp tutorial
1 parent adbd017 commit ed247ff

File tree

11 files changed

+163
-168
lines changed

11 files changed

+163
-168
lines changed

.changeset/cyan-countries-joke.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@kadena/docs': patch
3+
---
4+
5+
revision election dApp tutorial

packages/apps/docs/src/pages/build/guides/election-dapp-tutorial/01-getting-started.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ workspace. Kadena has developed a "PACT" extension for this editor. It features
5252
syntax highlighting, error reporting and code coverage reporting to improve your
5353
smart contract development workflow. The extension does require you to have `pact`
5454
and `pact-lsp` installed on your computer. You can configure the path to each
55-
executable in the plugin settings. If you are using another editor, you may also
56-
profit from just `pact-lsp` which provides the syntax highlighting. The links
55+
executable in the extension's settings. If you are using another editor, you may also
56+
profit from just `pact-lsp` which provides syntax highlighting for Pact code. The links
5757
to the installation instructions are listed on the
5858
[main page](/build/guides/election-dapp-tutorial) of this tutorial.
5959

@@ -67,7 +67,7 @@ Let's explore these folders one by one.
6767

6868
This is where the `.pact` files for your smart contracts go, as well as `.repl`
6969
files that will be used to test your smart contracts in isolation. You will
70-
notice a `./root` folder that already contains some `.pact` files. They contain
70+
notice a `./root` folder that already contains some `.pact` files. These files contain
7171
Pact modules that the smart contracts you will create in later chapters depend
7272
on. They only need to be there for local testing with `.repl` files. You do not
7373
need to deploy them to the blockchain alongside your own `.pact` files, because
@@ -81,11 +81,11 @@ For the front-end of the election website, a basic React app was created. You
8181
could use any other framework to create the front-end, because the connection
8282
with the blockchain is established through the
8383
[Kadena Client](https://www.npmjs.com/package/@kadena/client) npm package
84-
that can be imported in any JavaScript project. At the end of the line, this
84+
that can be imported in any JavaScript project. In the end, this
8585
package simply makes HTTP API requests to the blockchain.
86-
Inside of the React components, data is manipulated by calling service methods
87-
the services get a specific implementation of repositories injected, depending
88-
on the projects configuration. Initially, the project is configured to use
86+
Inside of the React components, data is manipulated by calling service methods.
87+
The services get a specific implementation of repositories injected, depending
88+
on the project's configuration. Initially, the project is configured to use
8989
the in-memory implementation of repositories. The in-memory repositories
9090
simply perform all data operations on JavaScript arrays and objects defined
9191
in the same file. This implementation was created for you to have a simple
@@ -99,9 +99,9 @@ repository implementation will be provided later in this chapter.
9999

100100
In this folder you will find several JavaScript snippets that use the Kadena
101101
Client library to perform actions against the blockchain that are not directly
102-
related to the functionality of the election dApp per se, like deploy and
102+
related to the functionality of the election dApp per se, like deploying and
103103
upgrading smart contracts, creating and funding accounts, and more. You will
104-
learn more about these snippets in the following chapters.
104+
learn more about these snippets in the upcoming chapters.
105105

106106
## Run the front-end
107107

@@ -115,7 +115,7 @@ npm install
115115
npm run start
116116
```
117117

118-
Open a browser window and visit `http://localhost:3000`. You will see the working
118+
Open a browser window and visit `http://localhost:5173`. You will see the working
119119
front-end of the election website. Because all data is manipulated in memory,
120120
you can freely click around and submit data. The state of the front-end will be
121121
reset as soon as you refresh the page. The website shows a list of candidates
@@ -132,5 +132,5 @@ At this point you should have a working development environment and an understan
132132
of the project structure. You have installed and run the front-end of the election
133133
website, and you have an understanding of its features. In the next chapter of this
134134
tutorial you will run a blockchain on your own computer using Docker. After that,
135-
you will be ready to start developing smart contracts and creating the Devnet
135+
you will be ready to start developing smart contracts and work on the Devnet
136136
implementations of the front-end repositories.

packages/apps/docs/src/pages/build/guides/election-dapp-tutorial/02-running-devnet.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Chainweaver will be executed against Devnet.
8787

8888
In Chainweaver, expand the left navigation bar and click contracts. Select
8989
`Module Explorer` at the top of the right panel to reveal a list of contracts
90-
that are already deployed on your Devnet. Next to the search box on top of
90+
that are already deployed on your Devnet. Next to the search box above
9191
that list, change `All chains` to any particular chain to narrow down the
9292
list to the unique contracts that are deployed to Devnet by default:
9393

@@ -119,7 +119,7 @@ documentation of the following functions:
119119

120120
* transfer
121121
* transfer-create
122-
* get-balance
122+
* details
123123
* create-account
124124

125125
These are some of the first smart contract functions that you will interact
@@ -214,7 +214,7 @@ your local Devnet:
214214
```
215215

216216
Notice that the list is exactly the same as the list displayed in the module
217-
explorer of Chainweaver. Both these tools can be used interchangably to interact
217+
explorer of Chainweaver. Both these tools can be used interchangeably to interact
218218
with the Kadena blockchain. They both support the execution of simple read
219219
operations as well as the execution of complex multi-step transactions, as will
220220
become clear when you will be using both approaches to test the smart contracts
@@ -229,7 +229,7 @@ are deployed on the Kadena networks by default and how you can explore them usin
229229
either Chainweaver or the Kadena JavaScript client. In the next chapter, you will
230230
create an account on Devnet. This account will govern several aspects of the smart
231231
contracts you will create in this tutorial: the namespace, keyset definition and
232-
module. The account will also get exclusive permission to call certain functions in the
232+
modules. The account will also get exclusive permission to call certain functions in the
233233
election smart contract, such as adding candidates. After setting up this account,
234234
namespace and keyset definitions, all will be in place to deploy the smart contract
235235
that will become the new back-end of the election website.

packages/apps/docs/src/pages/build/guides/election-dapp-tutorial/03-admin-account.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ via the top section of the
5252
navigation bar on the left side of the window. When you click `+ Generate Key` on the
5353
top right, a new public key will be added to the list of public keys. Click `Add k: Account`
5454
on the right of this new public key and your k:account will be added to the accounts
55-
that you are watching via Chainweaver. Expand the row of the account you justed added
55+
that you are watching via Chainweaver. Expand the row of the account you just added
5656
by clicking the arrow on the left side of the account name. You will see that no KDA balance
5757
exists for this account on any of the chains and the information about the owner and keyset
5858
of the account is missing. This indicates that your account does not yet exist on Devnet.
@@ -95,16 +95,16 @@ npm run generate-types:coin:devnet
9595

9696
Now you are ready to run the npm script that executes the snippet `./transferCreate.ts`. Open up this
9797
file in your editor to learn how the Kadena JavaScript client is used to call the `transfer-create`
98-
function of the `coin` module to create and fund your admin account. After importing the depencies
98+
function of the `coin` module to create and fund your admin account. After importing the dependencies
9999
and creating the client with the right (Devnet) configuration, the
100100
main function is called with information about the sender, the receiver and the amount. The amount
101-
of KDA to transfer to the receiver is hardcoded to 20. The receiver will be you admin account name,
101+
of KDA to transfer to the receiver is hardcoded to 20. The receiver will be your admin account name,
102102
which you will specify as an argument when running the script. The sender, `sender00`, is one
103103
of the pre-installed Devnet test accounts that holds some KDA on all chains. The public and private
104104
key for this account were copied over from GitHub. Inside the main function, the amount to transfer
105-
is converted to a PactDecimal, which boils down to this format: `{ decimal: '20.0' }`. Then, the
105+
is converted to a `PactDecimal`, which boils down to this format: `{ decimal: '20.0' }`. Then, the
106106
transaction is created. Creating this transaction is slightly more complex than the `list-modules`
107-
you learned about in the previous chapter.
107+
transaction you learned about in the previous chapter.
108108

109109
Instead of passing raw Pact code as a string to `Pact.builder.execution()`, the `coin['transferCreate']`
110110
function is called on `Pact.modules` to generate the correct Pact code for you, based on the
@@ -126,22 +126,26 @@ admin account. Replace `k:account` with your admin account.
126126
npm run transfer-create:devnet -- k:account
127127
```
128128

129-
After a few seconds, `Write succeeded` should be printed in the terminal window. Verify that your account was created by checking the account details using the Kadena JavaScript client.
129+
After a few seconds, `Write succeeded` should be printed in the terminal window. Verify that
130+
your account was created by checking the account details using the Kadena JavaScript client.
130131
Replace `k:account` with your admin account.
131132

132133
```bash
133134
npm run coin-details:devnet -- k:account
134135
```
135136

136137
This time, the script should print out the account name, the KDA balance and the receiver guard
137-
of the account. Chainweaver will tell the same story. Navigate to `Accounts` in the top section of the left menu bar. Expand your admin account to view the information on all chains. You will
138+
of the account. Chainweaver will tell the same story. Navigate to `Accounts` in the top section
139+
of the left menu bar. Expand your admin account to view the information on all chains. You will
138140
see that on chain 1 you are the owner, one keyset is defined and the balance is 20 KDA.
139141

140142
## Next steps
141143

142144
In this chapter you learned how to create a key for a Kadena account using Chainweaver and to
143145
create and fund this account using the Kadena JavaScript client. You verified the creation
144-
of the account in `Accounts` view of Chainweaver and by calling the `details` function of the `coin` module on Devnet using the Kadena JavaScript client. The admin user will use its KDA
145-
to pay gas fees charged for deploying keysets, deploying smart contracts and sending transactions to nominate candidates for the election. In the following chapter you will learn
146+
of the account in `Accounts` view of Chainweaver and by calling the `details` function of the
147+
`coin` module on Devnet using the Kadena JavaScript client. The admin user will use its KDA
148+
to pay gas fees charged for deploying keysets, deploying smart contract modules and sending
149+
transactions to nominate candidates for the election. In the following chapter you will learn
146150
how to create a namespace in which you will later define an admin keyset and deploy your
147151
smart contracts.

packages/apps/docs/src/pages/build/guides/election-dapp-tutorial/04-namespaces.md

+16-13
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ tags: [pact, smart contract, typescript, tutorial]
1010

1111
# Chapter 04: Namespaces
1212

13-
Toward the end of this tutorial you will deploy your election smart contract
14-
to Testnet. Everyone else who is following along with this tutorial will do the same.
15-
If everyone would deploy Pact modules with the same name, however, it would become impossible
16-
to distinguish your Pact module from all the others. Therefore, it is not allowed to
13+
After you have completed this entire tutorial, you may want to deploy your election
14+
smart contract to Testnet. Many others like you would perhaps like to do the same.
15+
If everyone would deploy Pact modules with the same name to the same network, however,
16+
it would become impossible to distinguish your Pact module from all the others. Therefore,
17+
it is not allowed to
1718
deploy a Pact module with a name that already exists on the chain you are deploying to
18-
and your deployment transaction will fail with an error if you would try. Fortunately,
19+
and your deployment transaction will fail with an error if you try. Fortunately,
1920
Kadena offers a solution to this problem by introducing namespaces. You can create
2021
your own unique namespace on the blockchain and you get to decide who can update the
2122
namespace or use it to define keysets and modules inside it. As long as you choose a
@@ -195,7 +196,7 @@ bottom of the `namespace.yml` file and run it.
195196
### Redefine the namespace as the new admin
196197

197198
To further prove that the namespace was successfully updated in the previous steps, it should
198-
be tested that the `user-keyset` will now be able to redefine the contract. You will need
199+
be tested that the `user-keyset` will now be able to redefine the namespace. You will need
199200
to load the signature of the `user-keyset` into the context of the Pact REPL and write a
200201
transaction to redefine the namespace. The transaction will be the same as the previous one,
201202
but this time it is wrapped inside an `expect` function instead of `expect-failure`.
@@ -221,21 +222,23 @@ Add the following transaction at the bottom of the `namespace.yml` file and run
221222
If all is well, `Load successful` will be displayed at the bottom of the output. In conclusion,
222223
you defined a namespace `election` and specified a keyset that is allowed to govern the
223224
namespace and a keyset that is allowed to use the namespace. You wrote an automated test
224-
script to verify that indeed only the governance keyset can redefine the namespace. The
225-
namespace was redefined in a way that handed over governance permissions to another keyset.
226-
Great work.
225+
script to verify that indeed only the governance keyset can redefine the namespace. Finally, the
226+
namespace was redefined in such a way that governance permissions were handed over to another
227+
keyset. Great work!
227228

228229
## Exercise: Define a principal namespace
229230

230231
Choosing an arbitrary namespace name like `election-your-name` still provides no guarantee
231232
that, by coincidence, this namespace is not already defined by someone else. To ensure
232233
that your namespace will be unique, you can create a principal namespace. The
233-
`create-principal-namespace` from the `ns` module creates a principle namespace name
234+
`create-principal-namespace` from the `ns` module creates a principal namespace name
234235
that is a hash of a keyset, prefixed with `n_`. In this example, you will use an `admin-keyset`
235236
that contains the public key of the `sender00` account, because `ns.create-principal-namespace`
236237
only accepts valid public keys inside the keyset. The `ns` module is readily available
237238
on Mainnet, Testnet and Devnet, but to use it in the Pact REPL it needs to be loaded
238-
from the local filesystem. The output of `ns.create-principal-namespace` called with the
239+
from the local filesystem. To that end, the `ns` module should be loaded from the local
240+
`./pact/root` folder of the project for testing purposes.The output of
241+
`ns.create-principal-namespace` called with the
239242
`admin-keyset` can be stored in a variable (`ns-name`) and passed to the `define-namespace`
240243
as the first argument. In the `./pact` folder create `principal-namespace.repl` file and paste the following
241244
code into it.
@@ -282,7 +285,7 @@ and holds KDA on chain 1. Otherwise, repeat the steps in the previous chapter to
282285
and fund your admin account. Chainweaver needs to remain open, because you will use
283286
it to sign the transaction for defining the namespace. Switch to your editor and open
284287
the file `./snippets/principal-namespace.ts`. The `pactCommand` variable contains the
285-
crucial bit of Pact code for defining a principle namespace, which you just tested in
288+
crucial bit of Pact code for defining a principal namespace, which you just tested in
286289
the Pact REPL. Also, recognize how the keyset data is added in a similar fashion as in
287290
the `.repl` file, with slightly different syntax. For the transaction on Devnet, a signer
288291
is also added, which was not required in the Pact REPL. After the transaction is defined,
@@ -311,7 +314,7 @@ If everything went well, you will see something similar to the following output.
311314
}
312315
```
313316

314-
Congratulations! You have defined a principle namespace on your local Devnet that
317+
Congratulations! You have defined a principal namespace on your local Devnet that
315318
can be governed and used by your admin account.
316319

317320
## Next steps

0 commit comments

Comments
 (0)