Skip to content

Commit 61ba7f1

Browse files
committed
update guides
1 parent 9bbccf5 commit 61ba7f1

File tree

12 files changed

+343
-408
lines changed

12 files changed

+343
-408
lines changed

apps/docs/content/docs/guides/aiken.mdx

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@ icon: "guides/aiken.png"
44
---
55
import Link from "fumadocs-core/link";
66

7-
Aiken is a functional programming language created for Cardano smart contract development. It prioritizes on-chain execution and offers a user-friendly approach for building secure and efficient smart contracts, making it a valuable choice for developers aiming to create robust on-chain applications.
7+
Aiken is a functional programming language for Cardano smart contract development. It prioritizes on-chain execution and offers a user-friendly approach for building secure and efficient smart contracts.
88

9-
In this tutorial, we will walk you through the process of writing a simple smart contract in Aiken, and create 2 transactions to lock and unlock assets on the Cardano blockchain.
10-
11-
You can also try the <Link href="https://aiken-template.meshjs.dev/">live demo</Link> and here are the codes on the <Link href="https://github.com/MeshJS/aiken-next-ts-template/tree/main">GitHub repository</Link>
9+
This tutorial walks you through writing a smart contract in Aiken and creating two transactions to lock and unlock assets on the Cardano blockchain.
1210

11+
Try the <Link href="https://aiken-template.meshjs.dev/">live demo</Link>. View the code on the <Link href="https://github.com/MeshJS/aiken-next-ts-template/tree/main">GitHub repository</Link>.
1312

1413
## System setup
1514

16-
This section will guide you through the process of setting up your system compile Aiken smart contracts. You can skip this section if you have already set up your system or do not wish to compile the contract.
15+
Set up your system to compile Aiken smart contracts. Skip this section if you have already set up your system or do not wish to compile the contract.
1716

18-
You can also check the installation instructions on the <Link href="https://aiken-lang.org/installation-instructions">Aiken website</Link> for more information.
17+
Check the installation instructions on the <Link href="https://aiken-lang.org/installation-instructions">Aiken website</Link> for more information.
1918

2019
### Using aikup (on Linux & MacOS only) [!toc]
2120

22-
If you are using Linux or MacOS, you can use the utility tool to download and manage Aiken's pre-compiled executables.
21+
Linux and MacOS users can use the utility tool to download and manage Aiken's pre-compiled executables.
2322

24-
You can install the Aiken CLI by running the following command in your terminal:
23+
Install the Aiken CLI:
2524

2625
```tsx
2726
$ curl -sSfL https://install.aiken-lang.org | bash
@@ -30,57 +29,56 @@ $ aikup
3029

3130
### From sources (all platforms) [!toc]
3231

33-
Aiken is written in Rust, so you will need to install Rust and Cargo to compile the smart contract. You can install Rust by following the instructions on the <Link href="https://www.rust-lang.org/">Rust website</Link>.
32+
Aiken is written in Rust. Install Rust and Cargo to compile the smart contract. Install Rust via the <Link href="https://www.rust-lang.org/">Rust website</Link>.
3433

35-
Next, you will need Cargo, the Rust package manager. You can install Cargo by following the instructions on the <Link href="https://doc.rust-lang.org/stable/book/ch01-01-installation.html">Cargo website</Link>.
34+
Install Cargo, the Rust package manager, via the <Link href="https://doc.rust-lang.org/stable/book/ch01-01-installation.html">Cargo website</Link>.
3635

37-
You will know you have successfully installed Rust and Cargo when you can run the following commands in your terminal:
36+
Verify installation:
3837

3938
```tsx
4039
$ rustc --version
4140
$ cargo --version
4241
```
4342

44-
Next, you will need to install the Aiken CLI. You can install the Aiken CLI by running the following command in your terminal:
43+
Install the Aiken CLI:
4544

4645
```tsx
4746
$ cargo install aiken
4847
```
4948

5049
### Check your installation [!toc]
5150

52-
You will know you have successfully installed the Aiken CLI when you can run the following command in your terminal:
51+
Verify the Aiken CLI installation:
5352

5453
```tsx
5554
$ aiken -V
5655
```
5756

58-
If you face any issues, please check the installation instructions on the <Link href="https://aiken-lang.org/installation-instructions">Aiken website</Link> for more information.
59-
57+
If issues arise, check the <Link href="https://aiken-lang.org/installation-instructions">Aiken website</Link>.
6058

6159
## Writing a smart contract with Aiken
6260

63-
In this section, we will walk you through the process of writing a simple smart contract in Aiken. We will also create 2 transactions to lock and unlock assets on the Cardano blockchain.
61+
Write a smart contract in Aiken and create two transactions to lock and unlock assets.
6462

65-
You can read more about this example on the <Link href="https://aiken-lang.org/example--hello-world/basics">Aiken website</Link>.
63+
Read more about this example on the <Link href="https://aiken-lang.org/example--hello-world/basics">Aiken website</Link>.
6664

6765
### Create a new project [!toc]
6866

69-
First, we will create a new project. Please refer to <Link href="/guides/nextjs">this guide</Link> for more information on creating a new Next.js project.
67+
Create a new project. Refer to <Link href="/guides/nextjs">this guide</Link> for creating a new Next.js project.
7068

71-
Next, we create a new Aiken project within this project folder:
69+
Create a new Aiken project within this project folder:
7270

7371
```tsx
7472
$ aiken meshjs/hello_world
7573
$ cd hello_world
7674
$ aiken check
7775
```
7876

79-
Remember to check your Aiken project by running `aiken check` after creating a new project and as you develop the contract.
77+
Run `aiken check` to verify your project.
8078

8179
### Write the smart contract [!toc]
8280

83-
Let's create file for our validator, `validators/hello_world.ak`:
81+
Create `validators/hello_world.ak`:
8482

8583
```tsx
8684
use aiken/hash.{Blake2b_224, Hash}
@@ -109,32 +107,31 @@ validator {
109107
}
110108
```
111109

112-
This validator checks that the redeemer message is "Hello, World!" and that the transaction is signed by the owner of the datum. If both conditions are met, the validator returns `true`. Otherwise, it returns `false`.
110+
This validator checks that the redeemer message is "Hello, World!" and that the transaction is signed by the datum owner. Returns `true` if both conditions are met; otherwise `false`.
113111

114-
Let's compile the smart contract with the Aiken CLI:
112+
Compile the smart contract:
115113

116114
```tsx
117115
$ aiken build
118116
```
119117

120-
This command will compile the smart contract and generate the `plutus.json` file in the root folder. This file is a <Link href="https://cips.cardano.org/cip/CIP-57">CIP-0057 Plutus blueprint</Link>, blueprint describes your on-chain contract and its binary interface.
121-
118+
This generates `plutus.json` in the root folder. This file is a <Link href="https://cips.cardano.org/cip/CIP-57">CIP-0057 Plutus blueprint</Link>, describing your on-chain contract and its binary interface.
122119

123120
## Creating locking transaction
124121

125122
### Preparing the frontend [!toc]
126123

127-
In this section, we will prepare the frontend for our smart contract. We will create a simple UI that allows users to lock and unlock assets on the Cardano blockchain.
124+
Prepare the frontend to allow users to lock and unlock assets.
128125

129-
Firstly, we need to install the `cbor` package:
126+
Install `cbor`:
130127

131128
```tsx
132129
$ npm install cbor
133130
```
134131

135-
Then, we create a folder, `data` and copy the `plutus.json` file into it.
132+
Create a `data` folder and copy `plutus.json` into it.
136133

137-
Next, open `pages/index.tsx` and import the following packages:
134+
Open `pages/index.tsx` and import the packages:
138135

139136
```tsx
140137
import {
@@ -153,7 +150,7 @@ import cbor from "cbor";
153150

154151
### Importing the contract [!toc]
155152

156-
We import the contract into our frontend:
153+
Import the contract:
157154

158155
```tsx
159156
const script: PlutusScript = {
@@ -165,13 +162,13 @@ const script: PlutusScript = {
165162
const scriptAddress = resolvePlutusScriptAddress(script, 0);
166163
```
167164

168-
Here, we are using the `plutus.json` file to create the script. We are also using the `resolvePlutusScriptAddress` function to resolve the script address.
165+
Use `plutus.json` to create the script and `resolvePlutusScriptAddress` to resolve the address.
169166

170-
If you look at it closely, we are encoding with cbor the compiled code of the validator. This is because the validator is encoded in a flat format, which is not the format expected by the cardano-cli and `cardano serialization library`.
167+
We encode the compiled validator code with cbor because the validator uses a flat format, unlike the format expected by cardano-cli and the serialization library.
171168

172169
### Locking assets [!toc]
173170

174-
We create the transactions to lock assets on the Cardano blockchain:
171+
Create the transaction to lock assets:
175172

176173
```tsx
177174
const hash = resolvePaymentKeyHash((await wallet.getUsedAddresses())[0]);
@@ -193,16 +190,15 @@ const signedTx = await wallet.signTx(unsignedTx);
193190
const txHash = await wallet.submitTx(signedTx);
194191
```
195192

196-
Here, we are creating a new transaction to lock assets on the Cardano blockchain. We are using the `resolvePaymentKeyHash` function to resolve the payment key hash of the wallet. We are also using the `sendLovelace` function to send lovelace to the script address.
197-
198-
As the contracts requires the owner's address in the datum field, we are creating a new datum with the owner's address. We are then using the `build` function to build the transaction, the `signTx` function to sign the transaction, and the `submitTx` function to submit the transaction to the Cardano blockchain.
193+
This transaction locks assets. `resolvePaymentKeyHash` resolves the wallet's key hash. `sendLovelace` sends lovelace to the script address.
199194

195+
The contract requires the owner's address in the datum. We build, sign, and submit the transaction.
200196

201197
## Unlocking assets
202198

203-
Next, we create the transactions to unlock assets.
199+
Create the transaction to unlock assets.
204200

205-
First, we create a useful function to retrieve the UTXO of the locked assets:
201+
Retrieve the UTXO of the locked assets:
206202

207203
```tsx
208204
async function _getAssetUtxo({ scriptAddress, asset, datum }) {
@@ -218,7 +214,7 @@ async function _getAssetUtxo({ scriptAddress, asset, datum }) {
218214
}
219215
```
220216

221-
And here are the codes to create the transactions to unlock assets:
217+
Create the unlock transaction:
222218

223219
```tsx
224220
const scriptAddress = resolvePlutusScriptAddress(script, 0);
@@ -254,10 +250,10 @@ const signedTx = await wallet.signTx(unsignedTx, true);
254250
const txHash = await wallet.submitTx(signedTx);
255251
```
256252

257-
Here, we are creating a new transaction to unlock assets on the Cardano blockchain. We are using the `resolvePlutusScriptAddress` function to resolve the script address. We are also using the `resolvePaymentKeyHash` function to resolve the payment key hash of the wallet.
253+
This transaction unlocks assets. `resolvePlutusScriptAddress` resolves the script address. `resolvePaymentKeyHash` resolves the wallet's key hash.
258254

259-
As the contracts requires the owner's address in the datum field, we are creating a new datum with the owner's address. We are then using the `_getAssetUtxo` function to retrieve the UTXO of the locked assets. We are then using the `redeemValue` function to redeem the locked assets, the `sendValue` function to send the assets to the owner's address, and the `setRequiredSigners` function to set the required signers.
255+
`_getAssetUtxo` retrieves the locked asset UTXO. `redeemValue` redeems the assets. `sendValue` sends assets to the owner. `setRequiredSigners` sets the required signers.
260256

261-
As the validator requires `Hello, World!` as the redeemer message, we are creating a new redeemer with the message `Hello, World!`. We are then using the `build` function to build the transaction, the `signTx` function to sign the transaction, and the `submitTx` function to submit the transaction to the Cardano blockchain.
257+
The validator requires "Hello, World!" as the redeemer message. We build, sign, and submit the transaction.
262258

263-
You can check the full code on <Link href="https://github.com/MeshJS/aiken-next-ts-template/blob/main/pages/index.tsx">GitHub</Link>.
259+
Check the full code on <Link href="https://github.com/MeshJS/aiken-next-ts-template/blob/main/pages/index.tsx">GitHub</Link>.

0 commit comments

Comments
 (0)