Skip to content

Latest commit

 

History

History
267 lines (217 loc) · 7.29 KB

README.md

File metadata and controls

267 lines (217 loc) · 7.29 KB

Trilio - A blockchain written in Python

Even though I don't know much about blockchain technology or how it works at all, I've decided to create my own blockchain with consensus algorithm Proof-of-Stake (PoS). I've lately been working with Solidity and been learning about smart-contract development, and during I found it quite fun and interesting. That is why this has and is a very fun project to work on, and even though it might not be classed as a blockchain I've learned a lot during research and improved my Python skills a lot!

UPDATE: I see a lot of things I could improve when I revisit this project.


Contributions are highly appreciated.

Benifits of Trilio

  • Ultra fast transactions.
  • Simple to understand and use.
  • Integrated smart-contract.

Requirements

Usage

Get started with Trilio

Installation

In order to make the installation much faster and simpler, I've uploaded this project to PyPi and you can simply install it using the pip command below.

$ pip install trilio==0.1.9

You might also need to pip install these libraries, too.

$ pip install datetime
$ pip install hashlib

Usage Examples

I guarantee you that if you try to understand you will understand. The code examples should
explain themselves.

Blockchain

Make your own Blockchain

from trilio import Trilio

blockchain = Trilio()

Validate your Blockchain

from trilio import Trilio

blockchain = Trilio()
valid = blockchain.validate_chain() # True = Valid, False = Invalid

Trilio's blockchain attributes

These blockchain attributes are already set, but you can change them to whatever you desire.

blockchain.trilio.difficulity = 5 # change the mining complexity

blockchain.trilio.name = "MyBlochainName" # change the name of your blockchain

blockchain.trilio.minimum_transactions = 1 # minimum transactions for each block

Wallet

Create a Wallet

from trilio import Trilio

blockchain = Trilio()
wallet = blockchain.Wallet.create_wallet() # Will return json with wallet information

Get wallet Keys

from trilio import Trilio

blockchain = Trilio()
wallet = blockchain.Wallet.create_wallet()
address = wallet["address"]
address["pve"] # Private key
address["pbc"] # Public key

Get wallet Attributes

blockchain.Wallet.get_balance(private_key=<private_key>, public_key=<public_key>) # Get a wallet's balance
blockchain.Wallet.get_assets(private_key=<private_key>, public_key=<public_key>) # Get a wallet's assets
blockchain.Wallet.get_collections(private_key=<private_key>, public_key=<public_key>) # Get a wallet's collections

Convert wallet Key

blockchain.Wallet.get_public_key(private_key=<private_key>)

Credit a Wallet

blockchain.Wallet.credit_wallet(public_key=<public_key>, amount=<amount>)

Validate a Wallet

blockchain.Wallet.validate_wallet(private_key=<private_key>, public_key=<public_key>) # True = found, False = not found

Transactions

Send tokens to Wallet

# Need to import datetime
blockchain.create_transaction(
    datetime.now(),
    data = {
        "type":"token-transfer",
        "data":{
            "to":<public_key (Wallet recieving)>,
            "from":<private_key (Wallet sending)>,
            "amount":<amount>
        }
    }
)

Send trade to Wallet (currently broken)

# Need to import datetime
blockchain.create_transaction(
    datetime.now(),
    data={
        "type":"asset-transfer",
        "data":{
            "_to":<public_key_receiver>,
            "_from":<private_key_sender>,
            "fassets":[<sending_assets_id>],
            "tassets":[<receiving_assets_id>]
        }
    }
)

Accept a Trade(currently broken)

# Need to import datetime
blockchain.create_transaction(
    datetime.now(),
    data={
        "type":"contract-action",
        "action":"accept-trade",
        "data":{
            "id":<trade_id>,
            "signer":<private_key>
        }
    }
)

Decline a Trade(currently broken)

# Need to import datetime
blockchain.create_transaction(
    datetime.now(),
    data={
        "type":"contract-action",
        "action":"decline-trade",
        "data":{
            "id":<trade_id>,
            "signer":<private_key>
        }
    }
)

Create your Collection

Collections are used to sort assets/NFTs to different categories, therefore we can also call collections "categories".

# Need to import datetime
blockchain.create_transaction(
    datetime.now(),
    data = {
        "type":"contract-action",
        "action":"collection-creation",
        "data":{
            "name":<collection_name>,
            "description":<collection_description>,
            "url":<collection_url>,
            "icon":<collection_icon>,
            "tags":<collection_tags>,
            "signer":<private_key>
        }
    }
)

#print(blockchain.Wallet.get_collections(private_key=<private_key>, public_key=<public_key>))

Create your Asset

Assets are basically a fancy name for NFTs, you would need a collection owned by you to mint an NFT.

# Need to import datetime
blockchain.create_transaction(
    datetime.now(),
    data={
        "type":"contract-action",
        "action":"asset-creation",
        "data":{
            "name":<asset_name>,
            "description":<asset_description>,
            "collection_id":<collection_id>,
            "quantity":<asset_mint_amount>,
            "signer":<private_key>
        }
    }
)

#print(blockchain.Wallet.get_assets(private_key=<private_key>, public_key=<public_key>))

Contact me

Discord: LocalMOD#3782

License

Check out Trilio's license.