Skip to content
Open
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
96 changes: 34 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,50 @@
# Seneca - Smart Contracts with Python
# Contracting - Smart Contracts on Lamden

<img src="https://github.com/Lamden/seneca/raw/master/seneca.jpg" align="right"
title="Seneca" width="300" height="450">
[![Join the chat at https://gitter.im/lamden-dev/Contracting](https://badges.gitter.im/lamden-dev/Contracting.svg)](https://gitter.im/lamden-dev/Contracting?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Smart contracts allow people to develop open agreements to do business in a way that is completely transparent, auditable, and automatable. Traditionally, smart contracting languages have been difficult for people to pick up. This is because early smart contract systems expose the differences between themselves and general programming languages through the development experience.
![Contracting](img/title.png)

Seneca is different because it focuses on the developer's point of view to provide an interface that feels as close to coding traditional systems as possible.
Contracting is the name of Lamden's smart contracting library. Unlike Bitcoin and Ethereum, Lamden leverages the existing PythonVM to create a system that allows developers to write small applications for the types of logic we see in smart contracts today. This generally has to do with simple logical transactions. Contracting focuses on making standard CRUD operations extremely easy with full support for JSON objects and dynamic storage sizing so you spend less time with lower level computer science details and more time coding.

## Install and Get Started
### Example
```python
def token_contract():
balances = Hash()
owner = Variable()

@construct
def seed():
owner.set(ctx.caller)

`coming soon`
@export
def balance_of(wallet_id):
return balances[wallet_id]

## Data Driven Model
@export
def transfer(to, amount):
sender_balance = balances[ctx.caller]

Most web based applications are driven by data: usernames, passwords, email addresses, profile pictures, etc. etc. However, smart contracts today do not provide clear interfaces to storing these complex data models.
assert sender_balance >= 0, "Sender balance must be non-negative!!!"

balances[ctx.caller] -= amount
balances[to] += amount

Seneca treats data like a tabular SQL table and smart contracts as a group of methods that creates, reads, updates, and deletes that data. This provides a very smooth development experience and a shallow learning curve to smart contracting.
@export
def mint(to, amount):
assert ctx.caller == owner.get(), 'Only the original contract author can mint!'
balances[to] += amount

```
ledger = st.create_table('ledger', [
('wallet_id', st.str_len(200), True),
('balance', int),
])

ledger.insert([{'wallet_id': 'carl', 'balance': 1000000}]).run()
```

## Clear Syntax

Seneca is Python. We restrict a lot of functionality, such as infinite loops, random number generation, etc., because it does not play well with the concepts found in the blockchain realm. But, the core syntax is 100% valid Python. You can run Seneca code on a plain MySQL database instance with the standard Python interpreter and it will function exactly as it will on the blockchain.
### Installing

## Straightforward Extendability
`pip install contracting`

Users (people like you!) are assigned a namespace which their smart contracts live on the blockchain based on their public key. This means that publishing smart contracts live in an open namespace that others can link to from their own smart contracts.

```
from carls_public_key import token

token.transfer_coins('carl', 100)
```

If you want to keep your smart contracts off limits, you can use our easy to use permissioning systems or simply not export the methods of your smart contract to the world. Methods on smart contracts are private by default so that permissioning hacks, [like the ones that Parity suffered](https://medium.com/@rtaylor30/how-i-snatched-your-153-037-eth-after-a-bad-tinder-date-d1d84422a50b), are less likely to occur.

```
...

def add_coins(wallet_id, amount_to_add):
assert amount_to_add >= 0, "It's not possible to 'add' a negative balance"

if not wallet_exists(wallet_id):
create_wallet(wallet_id)

old_balance = get_balance(wallet_id)
ledger.update({'balance': old_balance + amount_to_add}) \
.where(ledger.wallet_id == wallet_id).run()


def remove_coins(wallet_id, amount_to_remove):
assert wallet_exists(wallet_id), "Wallet id is not present in ledger"
assert amount_to_remove >= 0, "Removing negative balances not permitted"

old_balance = get_balance(wallet_id)
assert old_balance - amount_to_remove >= 0, "No negative balances allowed"
ledger.update({'balance': old_balance - amount_to_remove}) \
.where(ledger.wallet_id == wallet_id).run()

@export
def transfer_coins(receiver_id, amount):
sender_id = rt.global_run_data.author
_transfer_coins(sender_id, receiver_id, amount)

...
```
### Prerequisites
Contracting assumes you have a MongoDB instance running with total open access. If you are running Contracting in production, do not expose the MongoDB or modify the code so that you have tighter controls over who uses the system. Contracting was made for developing smart contracts and pushing them to Lamden's blockchain first. Alternative applications may have security risks associated with it.

## Why the name Seneca?
### Docs & More
Official docs and walkthrough are available [here](http://contracting.lamden.io).

Seneca was a Roman Stoic philosopher. The Stoics practiced logic, level-headedness, pragmatism, and critical thinking over emotion. We wanted to create a smart contracting language that was straightforward, made logical sense, and took few ideological stances.
Our team has produced a great walk-through for beginners which you can checkout [here](https://blog.lamden.io/smart-contracting-with-python-2af233620dca?gi=308f31362a75).