Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
You are building what you want. Why not also build how you want?
This is an implementation of smart contracts for Cardano which are written in a strict subset of valid Python. The general philosophy of this project is to write a compiler that ensure the following:
If the program compiles then:
Check out the eopsin-pioneer-program for a host of educational example contracts, test cases and off-chain code.
Check out the eopsin-example repository for a quick start in setting up a development environment and compiling some sample contracts yourself.
You can replace the contracts in your local copy of the repository with code from the
examples
section here to start exploring different contracts.
This repository contains a discussions page. Feel free to open up a new discussion with questions regarding development using eopsin and using certain features. Others may be able to help you and will also benefit from the previously shared questions.
Check out the community here
You can also chat with other developers in the welcoming discord community of OpShin
Install Python 3.8. Then run
python3.8 -m pip install eopsin-lang
A short non-complete introduction in starting to write smart contracts follows.
eopsin eval
to get a feeling for how they work.eopsin compile
and look at the compiler erros for guidance along what works and doesn't work and why.examples
to understand common patterns. Check out the prelude
for understanding how the Script Context is structured and how complex datums are defined.In summary, a smart contract in eopsin is defined by the function validator
in your contract file.
The function validates that a specific value can be spent, minted, burned, withdrawn etc, depending
on where it is invoked/used as a credential.
If the function fails (i.e. raises an error of any kind such as a KeyError
or AssertionError
)
the validation is denied, and the funds can not be spent, minted, burned etc.
There is a subtle difference here in comparison to most other Smart Contract languages. In eopsin a validator may return anything (in particular also
False
) - as long as it does not fail, the execution is considered valid. This is more similar to how contracts in Solidity always pass, unless they run out of gas or hit an error. So make sure toassert
what you want to ensure to hold for validation!
A simple contract called the "Gift Contract" verifies that only specific wallets can withdraw money.
They are authenticated by a signature.
If you don't understand what a pubkeyhash is and how this validates anything, check out this gentle introduction into Cardanos EUTxO.
Also see the tutorial by pycardano
for explanations on what each of the parameters to the validator means
and how to build transactions with the contract.
from eopsin.prelude import *
@dataclass()
class CancelDatum(PlutusData):
pubkeyhash: bytes
def validator(datum: CancelDatum, 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"
All contracts written in eopsin are 100% valid python.
Minting policies expect only a redeemer and script context as argument.
Check out the Architecture guide
for details on how to write double functioning contracts.
The examples
folder contains more examples.
Also check out the eopsin-pioneer-program
and eopsin-example repo.
Write your program in python. You may start with the content of examples
.
Arguments to scripts are passed in as Plutus Data objects in JSON notation.
You can run any of the following commands
# Evaluate script in Python - this can be used to make sure there are no obvious errors
eopsin eval examples/smart_contracts/assert_sum.py "{\"int\": 4}" "{\"int\": 38}" "{\"constructor\": 0, \"fields\": []}"
# Compile script to 'uplc', the Cardano Smart Contract assembly
eopsin compile examples/smart_contracts/assert_sum.py
The deploy process generates all artifacts required for usage with common libraries like pycardano, lucid and the cardano-cli.
# Automatically generate all artifacts needed for using this contract
eopsin build examples/smart_contracts/assert_sum.py
See the tutorial by pycardano
for explanations how to build transactions with eopsin
contracts.
Not every valid python program is a valid smart contract.
Not all language features of python will or can be supported.
The reasons are mainly of practical nature (i.e. we can't infer types when functions like eval
are allowed).
Specifically, only a pure subset of python is allowed.
Further, only immutable objects may be generated.
For your program to be accepted, make sure to only make use of language constructs supported by the compiler. You will be notified of which constructs are not supported when trying to compile.
Eopsin (Korean: 업신; Hanja: 業神) is the goddess of the storage and wealth in Korean mythology and shamanism. [...] Eopsin was believed to be a pitch-black snake that had ears. [1]
Since this project tries to merge Python (a large serpent) and Pluto/Plutus (Greek wealth gods), the name appears fitting.
The name is pronounced op-shin.
This program consists of a few independent components:
For debugging purposes, you can also run
# Compile script to 'uplc', and evaluate the script in UPLC (for debugging purposes)
python3 -m eopsin eval_uplc examples/smart_contracts/assert_sum.py "{\"int\": 4}" "{\"int\": 38}" "{\"constructor\": 0, \"fields\": []}"
# Compile script to 'pluto', an intermediate language (for debugging purposes)
python3 -m eopsin compile_pluto examples/smart_contracts/assert_sum.py
You can sponsor the development of eopsin through GitHub or Teiki or just by sending ADA. Drop me a message on social media and let me know what it is for.
$opshin
or addr1qyz3vgd5xxevjy2rvqevz9n7n7dney8n6hqggp23479fm6vwpj9clsvsf85cd4xc59zjztr5zwpummwckmzr2myjwjns74lhmr
.FAQs
A simple pythonic programming language for Smart Contracts on Cardano
We found that eopsin-lang demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.