Skip to content
Merged
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
26 changes: 18 additions & 8 deletions docs/smart-contracts/opshin.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This allows unit tests and verification of the Python code using standard toolin
Existing IDEs, linters and language servers may be re-used as well.
Note that the type system of opshin is much stricter than the type system of Python, so that many optimizations can be implemented and an elevated level of security is provided.

The language interacts closely with the python library [pycardano](https://pycardano.readthedocs.io/en/latest/index.html).
The language interacts closely with the python library [PyCardano](https://pycardano.readthedocs.io/en/latest/index.html).
The internal data structures are defined with data types compatible to the library and allow a tight combination of off- and on-chain code, all written in Python.

:::caution
Expand All @@ -26,9 +26,8 @@ opshin is a still a work in progress and is NOT recommended for use in productio

## Getting started

A tutorial on getting started with opshin may be found on [its GitHub page](https://github.com/OpShin/opshin).
Additionally, a tutorial demonstrating how to write matching off-chain code for opshin contracts can be found in the [pycardano documentation](https://pycardano.readthedocs.io/en/latest/guides/plutus.html).

A complete example on a small written contract and off-chain code to deploy it on-chain can be found in the [opshin-starter-kit](https://github.com/OpShin/opshin-starter-kit) repository.
It contains code that will compile the contract and deploy it to the preview testnet, runnable in demeter.run, in your browser.

### Example contract

Expand All @@ -37,23 +36,34 @@ This is a basic validator written in opshin:
```python
from opshin.prelude import *


@dataclass()
class CancelDatum(PlutusData):
class WithdrawDatum(PlutusData):
pubkeyhash: bytes


def validator(datum: CancelDatum, redeemer: None, context: ScriptContext) -> None:
def validator(datum: WithdrawDatum, redeemer: None, context: ScriptContext) -> None:
sig_present = False
for s in context.tx_info.signatories:
if datum.pubkeyhash == s:
sig_present = True
assert sig_present, "Required signature missing"
```

It checks the presence of a specific signature in the transaction to approve spending funds.
We can compile the contract like this

```bash
$ python3 -m pip install opshin
$ opshin build contract.py
```

The result is a directory filled with the contract address, policy ID and data that will be used by off-chain libraries to interact with the contract.


## Links
- [opshin Github Repository](https://github.com/OpShin/opshin).
- [opshin pioneer program](https://github.com/OpShin/opshin-pioneer-program)
- [opshin example project](https://github.com/OpShin/opshin-example)
- [pycardano Smart Contract documentation](https://pycardano.readthedocs.io/en/latest/guides/plutus.html).
- [opshin starter kit](https://github.com/OpShin/opshin-starter-kit)
- [PyCardano Smart Contract documentation](https://pycardano.readthedocs.io/en/latest/guides/plutus.html).