Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the "Using Plutus Tx" section of the user guide #6516

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ One final step before minting the token: since we want to lock the minted token
we must supply the parameters (i.e., `AuctionParams`) to the auction validator, compile the auction validator, and calculate its script address.

Open `GenAuctionValidatorBlueprint.hs` in the `on-chain` directory, and replace all placeholders:
- Replace `error "Replace with sellerh pkh"` with the content of `off-chain/seller.pkh`.
- Replace `error "Replace with seller pkh"` with the content of `off-chain/seller.pkh`.
- Replace `error "Replace with currency symbol"` with the minting policy hash, which you can find in the `hash` field in `off-chain/plutus-auction-minting-policy.json`.
- Replace `error "Replace with the auction's end time"` with a POSIX timestamp for a time in the near future (say 24 hours from now).
Note that the POSIX timestamp in Plutus is the number of _milliseconds_, rather than seconds, elapsed since January 1, 1970.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The following substitutions are needed:
- Substitute your Blockfrost project ID for `Replace with Blockfrost Project ID`.
- Substitute a slot number no later than the auction's end time for `Replace with transaction expiration time`.
For instance, if you set the auction's end time to be approximately 24 hours from now, you can use a slot number corresponding to approximately 12 hours from now.
To determine the slot nmber, go to [Cardanoscan](https://preview.cardanoscan.io/), click on a recent transaction, take its Absolute Slot, and add 12 hours (43200) to it.
To determine the slot number, go to [Cardanoscan](https://preview.cardanoscan.io/), click on a recent transaction, take its Absolute Slot, and add 12 hours (43200) to it.

Place the first bid by running

Expand Down
4 changes: 2 additions & 2 deletions doc/docusaurus/docs/auction-smart-contract/on-chain-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar_position: 5

:::caution
The code in this example is not a production-ready implementation, as it is not optimized for security or efficiency.
It is provided purely as an example for illustration and ecudational purposes.
It is provided purely as an example for illustration and educational purposes.
Refer to resources like **[Cardano Plutus Script Vulnerability Guide](https://library.mlabs.city/common-plutus-security-vulnerabilities)** for best practices on developing secure smart contracts.
:::

Expand Down Expand Up @@ -63,7 +63,7 @@ In our example, our validator verifies several conditions of the transaction; e.

Different [ledger language versions](../working-with-scripts/ledger-language-version.md) use different script context types.
In this example we are writing a Plutus V2 scripts, so we import the `ScriptContext` data type from `PlutusLedgerApi.V2.Contexts`.
It can be easiely adapted for Plutus V1 or V3.
It can be easily adapted for Plutus V1 or V3.

> :pushpin: **NOTE**
>
Expand Down
4 changes: 2 additions & 2 deletions doc/docusaurus/docs/delve-deeper/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ By crafting a new language from scratch, you avoid inheriting the limitations an
On the other hand, standalone DSLs have some disadvantages.
First, designing and implementing them can be challenging.
Not only must the syntax and semantics be created from scratch, but you also need to build all necessary compiler components, tooling, and a library ecosystem from the ground up.
This can be a formidable task, as developing, testing, and maintaining compilers and tooling, along with establishing and maintining a library ecosystem, require substantial efforts, particularly with the addition of new language features over time.
This can be a formidable task, as developing, testing, and maintaining compilers and tooling, along with establishing and maintaining a library ecosystem, require substantial efforts, particularly with the addition of new language features over time.

Second, users will need to adopt a new programming language and incorporate it into their existing tech stacks.
This can present a considerable challenge, as it involves a learning curve, increased cognitive load, and the necessity to introduce and manage additional tools.
Expand All @@ -36,7 +36,7 @@ This can present a considerable challenge, as it involves a learning curve, incr
An embedded DSL (commonly referred to as an eDSL) generally takes the form of a library in a host programming language.
Functional languages such as Haskell are particularly well-suited for hosting eDSLs, as the implementation of an eDSL largely involves functions that construct and transform abstract syntax trees (ASTs).

Embedded DSLs can be much easier than standlone DSLs to develop, and to integrate into projects that already use the host language.
Embedded DSLs can be much easier than standalone DSLs to develop, and to integrate into projects that already use the host language.
Embedded DSLs, however, come with the drawback that the complexity of constructing and manipulating ASTs are exposed to the users.
When using an embedded DSL, you are essentially writing programs that create and manage ASTs, rather than straightforward code.

Expand Down
2 changes: 1 addition & 1 deletion doc/docusaurus/docs/essential-concepts/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ When evaluating a standalone program using the `uplc` executable, flag `-S` or `

Several Plutus components are regularly released as libraries, such as `plutus-core`, `plutus-ledger-api` and `plutus-tx-plugin`.
These packages are published on the [Cardano Haskell Package repository](https://github.com/IntersectMBO/cardano-haskell-packages) (CHaP), rather than Hackage, Haskell's default package archive.
Each release has a version following a standard release versioning scheme, and this is completely orthogonal and irrelevant to all other aformentioned notions of version.
Each release has a version following a standard release versioning scheme, and this is completely orthogonal and irrelevant to all other aforementioned notions of version.
31 changes: 0 additions & 31 deletions doc/docusaurus/docs/getting-started-plutus-tx.md

This file was deleted.

2 changes: 1 addition & 1 deletion doc/docusaurus/docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ See [_The Extended UTXO Model_](https://iohk.io/en/research/library/papers/the-e

### Guardrail Script

A guardrail script, sometimes referred to as a consitution script or a proposing script, is a Plutus V3 script used to validate two kinds of governance actions: parameter change and treasury withdrawal.
A guardrail script, sometimes referred to as a constitution script or a proposing script, is a Plutus V3 script used to validate two kinds of governance actions: parameter change and treasury withdrawal.
See [Script Purposes](./working-with-scripts/script-purposes.md).

### Hard Fork
Expand Down
33 changes: 15 additions & 18 deletions doc/docusaurus/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,50 @@ sidebar_position: 0

## Introduction

Plutus is the native smart contract language for the Cardano ecosystem.
Plutus is the native smart contract language for the Cardano ecosystem.

The Plutus project consists of:
- Plutus Core, the programming language used for scripts on Cardano;
- Tooling and compilers for compiling various intermediate languages into Plutus Core; and
- Plutus Tx, the compiler that compiles the Haskell source code into Plutus Core to form the on-chain part of a contract application.
The Plutus project consists of:
- Plutus Core, the programming language used for scripts on Cardano;
- Tooling and compilers for compiling various intermediate languages into Plutus Core; and
- Plutus Tx, the compiler that compiles the Haskell source code into Plutus Core to form the on-chain part of a contract application.

All of these elements are used in combination to write Plutus Core scripts that run on the Cardano blockchain.

To develop and deploy a smart contract, you also need off-chain code for building transactions, submitting transactions, deploying smart contracts, querying for available UTXOs on the chain, and so on. You may also want a front-end interface for your smart contract for a better user experience.
To develop and deploy a smart contract, you also need off-chain code for building transactions, submitting transactions, deploying smart contracts, querying for available UTXOs on the chain, and so on. You may also want a front-end interface for your smart contract for a better user experience.

Plutus allows all programming to be done from a [single Haskell library](https://plutus.cardano.intersectmbo.org/haddock/latest). This lets developers build secure applications, forge new assets, and create smart contracts in a predictable, deterministic environment with the highest level of assurance. Furthemore, developers don’t have to run a full Cardano node to test their work.
Plutus allows all programming to be done from a [single Haskell library](https://plutus.cardano.intersectmbo.org/haddock/latest). This lets developers build secure applications, forge new assets, and create smart contracts in a predictable, deterministic environment with the highest level of assurance. Furthermore, developers don’t have to run a full Cardano node to test their work.

With Plutus you can:

- Forge new tokens in a lightweight environment,
- Build smart contracts, and
- Support basic multi-sig scripts.

## Getting started with Plutus Tx
See [Getting started with Plutus Tx](getting-started-plutus-tx.md) if you want to jump right in and start a project.

## Intended audience

The intended audience of this documentation includes developers who want to implement smart contracts on the Cardano blockchain.
The intended audience of this documentation includes developers who want to implement smart contracts on the Cardano blockchain.
This involves using Plutus Tx to write scripts, requiring some knowledge of the Haskell programming language.

This guide is also meant for certification companies, certification auditors, and people who need an accurate specification.
This guide is also meant for certification companies, certification auditors, and people who need an accurate specification.
See, for example:

- the [Cardano ledger specification](https://github.com/IntersectMBO/cardano-ledger#cardano-ledger)
- the [Plutus Core specification](https://github.com/IntersectMBO/plutus#specifications-and-design)
- the [public Plutus code libraries](https://plutus.cardano.intersectmbo.org/haddock/latest) generated using Haddock.
- the [public Plutus code libraries](https://plutus.cardano.intersectmbo.org/haddock/latest) generated using Haddock.

## The Plutus repository

The [Plutus repository](https://github.com/IntersectMBO/plutus) includes:
The [Plutus repository](https://github.com/IntersectMBO/plutus) includes:

* the implementation, specification, and mechanized metatheory of Plutus Core
* the Plutus Tx compiler
* the implementation, specification, and mechanized metatheory of Plutus Core
* the Plutus Tx compiler
* the combined documentation, generated using Haddock, for all the [public Plutus code libraries](https://plutus.cardano.intersectmbo.org/haddock/latest), such as `PlutusTx.List`, enabling developers to write Haskell code that can be compiled to Plutus Core.

## Educational resources

The IOG Education Team provides the IOG Academy Haskell Course and the Plutus Pioneer Program (PPP) to attract and train software developers in Plutus.
The IOG Education Team provides the IOG Academy Haskell Course and the Plutus Pioneer Program (PPP) to attract and train software developers in Plutus.

If you are new to Plutus or are looking for additional educational material, please see the following resources:
If you are new to Plutus or are looking for additional educational material, please see the following resources:

- [IOG Academy Haskell Course](https://www.youtube.com/playlist?list=PLNEK_Ejlx3x1D9Vq5kqeC3ZDEP7in4dqb)
- [Plutus Pioneer Program Gitbook](https://iog-academy.gitbook.io/plutus-pioneers-program-fourth-cohort/)
Expand Down
10 changes: 5 additions & 5 deletions doc/docusaurus/docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ sidebar_position: 80

This means the plugin cannot access to the definition of a Haskell identifier, which it needs to be able to compile that identifier to Plutus Core.

If the identifier in question is defined in the source code, try adding the `INLINABLE` pragma to it (not the `INLINE` pragma, which should generally be avoided).
If it already has the `INLINABLE` pragma, try adding the GHC flags
If the identifier in question is defined in the source code, try adding the `INLINEABLE` pragma to it (not the `INLINE` pragma, which should generally be avoided).
If it already has the `INLINEABLE` pragma, try adding the GHC flags
`-fno-ignore-interface-pragmas` and `-fno-omit-interface-pragmas`.

If this doesn't resolve the issue, or if the identifier in question isn't directly defined in the code but is produced by GHC optimizations,
ensure that you apply all GHC flags listed in [Compiling Plutus Tx](./using-plutus-tx/compiling-plutus-tx.md).
ensure that you apply all GHC flags listed in [GHC Extensions, Flags and Pragmas](./using-plutus-tx/extensions-flags-pragmas.md).
These flags disable GHC optimizations that can interfere with the plugin, and ensure that unfoldings are neither omitted nor ignored.

If the identifier with missing unfolding is from `base` or invoked by a function from `base`, you should use instead the corresponding function from the `plutus-tx` package.
Expand Down Expand Up @@ -47,7 +47,7 @@ case (x :: Maybe Integer) of Just y | y PlutusTx.== 42 -> ...

### "Unsupported feature: Cannot construct a value of type"

Conversely, to convert a Haskell type to the correspoding builtin type in Plutus Tx, you should use `toOpaque`, rather than directly using the data constructor or `toBuiltin`.
Conversely, to convert a Haskell type to the corresponding builtin type in Plutus Tx, you should use `toOpaque`, rather than directly using the data constructor or `toBuiltin`.

## Runtime Issues

Expand All @@ -60,7 +60,7 @@ If your expected trace messages are missing, check the following [plugin flags](

### Unexpected Evaluation Failure

It is usually [advisable](./using-plutus-tx/compiling-plutus-tx) to use the `Strict` extension when writing Plutus Tx, which improves performance.
It is usually [advisable](./using-plutus-tx/extensions-flags-pragmas.md) to use the `Strict` extension when writing Plutus Tx, which improves performance.
However, be cautious, as this can result in unexpected evaluation failures.
Consider the following script:

Expand Down
3 changes: 1 addition & 2 deletions doc/docusaurus/docs/using-plutus-tx/_category_.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"label": "Using Plutus Tx",
"position": 40,
"link": {
"type": "generated-index",
"description": "This section guides you through a full spectrum of ideas, from foundational concepts to advanced techniques to help you learn how to use Plutus Tx effectively. "
"type": "generated-index"
}
}

This file was deleted.

This file was deleted.

Loading