Deploying a standard contract, binded contract or term

From the concepts we have covered thus far. You should know how to send or get data from the blockchain. A smart contract is basically executable code stored on the blockchain. The node produces proof that the contract ran to the requester and then decentralises the result of the contract.

In Kujua all contracts are written in Python without imported libraries. Meaning that you need to remove or comment out all imports from your contract before deployment. Contract supported modules (for security reasons) are those that come built-in with Python itself, those whitelisted for contract usage, including those used by a standard unaltered node setup which include:

flask,
flask_api,
sqlalchemy,
cryptography,
base64,
requests,
multiprocessing,
threading,
datetime,
hashlib,
ast,
collections,
sys,
dateutil,
os,
binascii,
argparse,
re,
random,
string,
pandas,
numpy

If you import libraries other than those listed your code may fail to execute. Be careful to test your code for errors before deploying as you cannot make changes to it once deployed and therefore not receive support.

When you deploy, the contract needs to be associated with a non-existent address, meaning a new address without a lineage. Contracts are not allowed to transact further using the 'cx', 'bx' or 'tx' address types but the funds can be transacted out from the contract address using a standard '0x' address type that owns the private key.

When you deploy your contract, the contract code is attached to the first ever transaction packet on data point ‘sender_template_readable_obj’.

Example of constructing a smart contract

This is an example of a contract on Kujua. In this specific contract we will be adding n days to todays date (utc) and returning the result.
Notice that the imports in your script are not included or commented out. All modules that a node supports for contracts are imported with a trailing _jua outside of the contract code therefore make sure your references to those modules also include the trailing _jua.
Because these modules support a wide range of use cases, your scripts need to be written with full import styles such as datetime.datetime.utcnow() as the node that supports contracts would have imported datetime as 'import datetime' and not 'from datetime import datetime'. Those are just examples, in reality the actual import will look like 'import datetime as datetime_jua'

Note: Kujua allows dynamic contracts (experimentally for now) so be careful if you allow your contract to pass arguments and be strict with your requirements.


import datetime as datetime_jua

example_code = """
class Contract():
    def results(self, days, passed_results: dict):
        calculated_date = (datetime_jua.datetime.utcnow() + datetime_jua.timedelta(days=days)).strftime("%Y-%m-%d")
        return {'status': 'complete', 'contents': "{} days from today the date will be {}".format(days, calculated_date)}

contract = Contract()
"""

# This is how a contract executes
contract_locals = {}
contract = exec(example_code, globals(), contract_locals)
Contract = contract_locals['contract']
results = Contract.results(3)  # NB: because Kujua allows dynamic contracts as well, be careful if you allow your contract to pass arguments and be strict with your requirements
print(results)

data points: sender_template_readable_obj

We use the on chain method by importing kujuaOnChain. Meaning the functions run directly on the node and return results. Off chain will be available with the full Github release. You can find the code for kujuaOnChain on GitHub