Build without limits

A pythonic programming language

  • 100% valid Python 3
  • Strong static typing with inference
  • Intuitive coding, the way you are used to
  • Loops, custom types, recursion, imports...
from opshin.prelude import *

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

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"

Focused on accessability

  • Quick and friendly feedback with helpful error diagnotics
  • Supported by basically every IDE
  • Produce highly efficient code
  • Interacts with python off-chain toolchains natively
$ opshin build gift.py
Traceback (most recent call last):
  File "./venv/bin/opshin", line 6, in <module>
    sys.exit(main())
  File "./opshin/__main__.py", line 138, in main
    raise SyntaxError(
  File "gift.py", line 8
    sig_present = datum in context.tx_info.signatories
                 ^
NotImplementedError: Comparison In for RecordType and ListType is not implemented. This is likely intended because it would always evaluate to False.
Note that opshin errors may be overly restrictive as they aim to prevent code with unintended consequences.

Leverage the Python ecosystem!

  • Zero configuration, one single capable tool
  • Unittests, property based tests, formal verification...
  • Syntax Highlighting, linting, static analysis...
  • Deeply integrated with PyCardano for transaction building
$ python3 -m pytest
========================================================================================================================== test session starts ===========================================================================================================================
platform linux -- Python 3.10.6, pytest-7.2.2, pluggy-1.0.0
rootdir: ./opshin-pioneer-program
plugins: typeguard-2.13.3, hypothesis-6.70.2
collected 107 items                                                                                                                                                                                                                                                      

src/week02/tests/test_homework.py ...F.FF.....                                                                                                                                                                                                                     [ 11%]
src/week02/tests/test_lecture.py .....                                                                                                                                                                                                                             [ 15%]
src/week03/tests/test_homework.py ....FFF.F.......FFFFFFFFF...                                                                                                                                                                                                     [ 42%]
src/week03/tests/test_lecture.py ..                                                                                                                                                                                                                                [ 43%]
src/week04/tests/test_homework.py ..........................                                                                                                                                                                                                       [ 68%]
src/week05/tests/test_homework.py ....FFF.F....F.F...F...F.......                                                                                                                                                                                                  [ 97%]
src/week05/tests/test_lecture.py ...         

What is OpShin?

OpShin is a new programming language and toolchain for developing smart contracts on the Cardano blockchain. It is focusing on accessability and developer experience.


OpShin is 100% valid Python 3. In this way it can seamlessly integrate with off-chain tools built in Python such as PyCardano. It can also leverage the existing testing frameworks and IDEs and allows developers to re-use knowledge or focus on attaining knowledge about a simple and general purpose language.

Why build another smart contract language?

Haskell is hard and almost no developer is used to it. On the other hand, Python is praised for its simplicity and used in almost 25% of all projects on the internet (compare that to roughly 0.65% for Haskell). So the ecosystem for Python is huge and full of interesting tools that leverage the developer experience.


The toolchain based on python can leverage these tools to provide a safe and enjoyable developer experience.

Is Python the right language for smart contracts? It's not even type safe right?

We chose Python because it is simple and intuitive. This is a great basis to improve security of contracts - if they are easy to read and understand, a larger group of people can interpret them.


To combat the problems that come with dynamically typed languages, OpShin enforces a strict type system on top of Python, similar to the Haskell type system. Hence, you enjoy the simplicy of Python programming and the safety of properly typed code.

I thought Cardano smart contracts had to be written in Haskell?

This is a common misconception. The current Cardano node implementation does indeed happen to be written in Haskell. The virtual machine for executing smart contracts that comes baked into the node is also implemented in Haskell. But that does not mean that it is Haskell which is executed by the smart contract virtual machine.


The virtual machine is a language interpreter which executes a smart contract language called 'Untyped Plutus Core' (abbrev. UPLC) often referred to simply as 'Plutus'.


Yet UPLC isn't something developers are expected to write by hand. Instead, it is a compilation target (like WebAssembly for the world wide web). Oddly enough, until recently, the only established framework that produced UPLC from a high-level syntax was called 'Plutus-Tx' and happened to be a Haskell framework.


OpShin changes the game by introducing a new framework that compiles straight to UPLC.

Can I write off-chain/backend code with OpShin?

No, but you can use the off-chain library PyCardano with which OpShin is closely integrated!


In PyCardano, you can natively import and handle the functions and classes you defined for your contract - this lets you build off-chain code that matches the contract frictionless.


The OpShin Starter Kit provides a practical example on how to use PyCardano and OpShin in symbiosis.